package com.fsnbigdata.service.impl;

import com.fsnbigdata.domain.Document;
import com.fsnbigdata.domain.Organism;
import com.fsnbigdata.domain.ZhDiversityReport;
import com.fsnbigdata.repository.ConservationStatusRepository;
import com.fsnbigdata.repository.DistributionRepository;
import com.fsnbigdata.repository.DiversityReportRepository;
import com.fsnbigdata.repository.OrganismRepository;
import com.fsnbigdata.repository.TaxonomyRepository;
import com.fsnbigdata.service.api.DiversityReportService;
import com.fsnbigdata.service.api.DocumentService;
import com.fsnbigdata.util.SortTools;
import com.fsnbigdata.vo.Tree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sun.rmi.log.LogInputStream;

import java.beans.Transient;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

@Service
public class DiversityReportServiceImpl implements DiversityReportService {

    @Autowired
    private DiversityReportRepository diversityReportRepository;

    @Autowired
    private DistributionRepository distributionRepository;    //用于查询地区物种id集合

    @Autowired
    private TaxonomyRepository taxonomyRepository;          //用于查询分类信息

    @Autowired
    private ConservationStatusRepository conservationStatusRepository;    //用于查询濒危部分信息
    
    @Autowired
    private OrganismRepository organismService;

    @Autowired
    private DocumentService documentService;
    


    @Autowired
    private OrganismRepository organismRepository;   //用于查询物种列表

    //临时用的替换文本类
    class Replace{
        String wordName;
        String newData;

        public Replace(String wordName, String newData) {
            this.wordName = wordName;
            this.newData = newData;
        }

        public Replace() {
        }

        public String getWordName() {
            return wordName;
        }

        public void setWordName(String wordName) {
            this.wordName = wordName;
        }

        public String getNewData() {
            return newData;
        }

        public void setNewData(String newData) {
            this.newData = newData;
        }
    }
    
    @Override
    public List<ZhDiversityReport> findAllByTitleLike(String title) {
        return diversityReportRepository.findAllByTitleLike(title);
    }

    @Override
    @Transactional
    public ZhDiversityReport setDocs(ZhDiversityReport zhDiversityReport, Iterable<Long> docs) {
        List<Document> items = documentService.findAll(docs);
        items.forEach(item -> {
            item.getOrganisms().size();
            item.getSpecimens().size();
        });
        Set<Document> currents = zhDiversityReport.getDocs();
        Set<Document> toRemove = new HashSet<Document>();
        for (Iterator<Document> iterator = currents.iterator(); iterator.hasNext(); ) {
            Document nextDocument = iterator.next();
            if (items.contains(nextDocument)) {
                items.remove(nextDocument);
            } else {
                toRemove.add(nextDocument);
            }
        }
        zhDiversityReport.removeFromDocs(toRemove);
        zhDiversityReport.addToDocs(items);
        // Force the version update of the parent side to know that the parent has changed
        // because it has new books assigned
        //TODO organism.setVersion(organism.getVersion() + 1);
        return diversityReportRepository.save(zhDiversityReport);
    }
    
    @Override
    public ZhDiversityReport findById(long id) {
        return diversityReportRepository.findOne(id);
    }
    
    @Override
    public List<ZhDiversityReport> findAll() {
        return diversityReportRepository.findAll();
    }
    
    @Override
    public ZhDiversityReport save(ZhDiversityReport zhDiversityReport) {
        return diversityReportRepository.save(zhDiversityReport);
    }
    
    @Override
    public ZhDiversityReport update(ZhDiversityReport zhDiversityReport) {
        return diversityReportRepository.save(zhDiversityReport);
    }

    @Transactional
    @Override
    public void deleteOne(Long id) {
        diversityReportRepository.deleteDocument(id);
        diversityReportRepository.deleteOne(id);
    }
    
    @Override
    public void deleteMany(Iterable<Long> ids) {
        List<ZhDiversityReport> zhDiversityReports = diversityReportRepository.findAll(ids);
        diversityReportRepository.delete(zhDiversityReports);
    }

    @Override
    public String getContent(ZhDiversityReport zhDiversityReport) throws Exception{
//    public String getContent(String province,String city,String county,String wetland,String weland) throws Exception{
        //读取txt文档
        BufferedReader br = new BufferedReader(new InputStreamReader(new ClassPathResource("model.txt").getInputStream()));
        String content = null;
        String s = null;
        StringBuffer stringBuffer = new StringBuffer();
        String province = zhDiversityReport.getProvince();
        String city = zhDiversityReport.getCity();
        String county = zhDiversityReport.getCounty();
        String wetland = zhDiversityReport.getWetland_type4();
        String weland = zhDiversityReport.getWetland_type5();
        //循环获取文档内容
        while ((s = br.readLine()) != null) {
            stringBuffer.append(s);
        }
        br.close();
        content = stringBuffer+"".replaceAll("\t", "");
         //省对应物种id集合
        List<Long> id = distributionRepository.queryIdByProvince( "贵州" );
        List<Long> ids = new ArrayList <>(  );
        if(zhDiversityReport.getIs_protection()==1){
            //保存时，如果是保护区，county代表保护区名字
            ids = distributionRepository.queryProtection(county);
        }else {
            //省下面的区域id集合
            if(county!=null&&!("".equals( county ))){
                ids = distributionRepository.queryCounty( province, city, county );
            }else {
                List<Object> listCityIds =  distributionRepository.findIdByCity( city );
                for (Object o:listCityIds){
                    ids.add( Long.parseLong( ""+o ) );
                }
            }
        }

        content = testWordContent(content,id,ids,wetland,weland );
        //方法的调用
        content = getContent2( content,id,ids );

        content = getContent3(content,id,ids);
        return content;
    }

    @Override
    public List getArea(String city) {
        class NewTree{
            String name;

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }
        }
        List trees = new ArrayList <>(  );
        if(city!=null&&!("".equals( city ))){
            for(String s:diversityReportRepository.getCounty(city)){
                if(s==null||"".equals( s )){
                    continue;
                }
                NewTree tree = new NewTree();
                tree.setName( s );
                trees.add( tree );
            }
        }else {
            for(String s:diversityReportRepository.getCity()){
                if(s==null||"".equals( s )){
                    continue;
                }
                Tree tree = new Tree();
                tree.setName( s );
                tree.setChildren( new ArrayList <>(  ) );
                trees.add( tree );
            }
            NewTree tree = new NewTree();
            tree.setName( "保护区" );
            trees.add( tree );
        }
        return trees;
    }

    @Override
    public List getPageList(String city, String county, Pageable pageable) {
        List list = new ArrayList(  );
        Pageable pageable1=new PageRequest(pageable.getPageNumber(),pageable.getPageSize(), SortTools.basicSort("desc","update_time"));
        if(county!=null&&!("".equals( county ))){
            list.add( diversityReportRepository.getCountByCityAndCounty( city,county ) );
            list.add( diversityReportRepository.getPageListByCityAndCounty(city,county,pageable1) ) ;
        }else{
            if("保护区".equals( city )){
                list.add( diversityReportRepository.getCount( ) );
                list.add( diversityReportRepository.getPageList(pageable1)  ) ;
            }else {
                list.add( diversityReportRepository.getCountByCity( city ) );
                list.add( diversityReportRepository.getPageListByCity(city,pageable1) ) ;
            }
        }
        return list;
    }

    @Override
    public List getList(String title, Pageable pageable) {
        List list = new ArrayList(  );
        list.add( diversityReportRepository.getCountByTitle(title) );
        list.add( diversityReportRepository.getAllListByTitle(title,pageable) );
        return list;
    }

    @Override
    public String testWords() throws Exception {
        //读取txt文档
        BufferedReader br = new BufferedReader(new InputStreamReader(new ClassPathResource("model.txt").getInputStream()));
        String content = null;
        String s = null;
        StringBuffer stringBuffer = new StringBuffer();
        //循环获取文档内容
        while ((s = br.readLine()) != null) {
            stringBuffer.append(s);
        }
        br.close();
        content = stringBuffer.toString().replaceAll("\t", "");
        List<Object> listCityIds =  distributionRepository.findIdByCity( "贵阳市" );
        List<Long> ids = new ArrayList <>();
        List<Long> id = distributionRepository.queryIdByProvince( "贵州" );
        //市及下物种id
        for (Object o:listCityIds){
            ids.add( Long.parseLong( ""+o ) );
        }
        //方法的调用
        content = getContent3(content,id,ids );
        return content;
    }

    /**
     * 获取附件内容
     * @param province
     * @param city
     * @param county
     * @param sign
     * @return
     */
    @Override
    public List<String> getAccessory(String province , String city, String county, String sign) {
        String fileName = "";
        List<Long> areaIds = new ArrayList <>(  );
        if(county.indexOf( "保护区" )==-1){
            areaIds = distributionRepository.getIds( county,province,city);
            fileName = (province!=null?province:"")+(city!=null?city:"")+(county!=null?county:"");
        }else {
            areaIds= distributionRepository.getIdsByCountryAndProvinceAndCityAndIds( null,null,null,county,null,null);
            fileName =county;
        }
        List<Long> ids = new ArrayList <>(  );
        List<String> list = new ArrayList(  );
        String content = "";
        switch (sign){
            case "1":
                fileName = fileName+"动物名录";
                ids = diversityReportRepository.getAnimaisByKingdom1();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom1( judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "2":
                fileName = fileName+"植物名录";
                ids = diversityReportRepository.getAnimaisByKingdom2();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom1( judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "3":
                fileName = fileName+"微生物名录";
                ids = diversityReportRepository.getAnimaisByKingdom3();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom1( judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "4":
                fileName = fileName+"中国特有物种名录";
                content = getContent( fileName,diversityReportRepository.getAnimaisByKingdom4( judgeIds( areaIds ) ) );
                break;
            case "5":
                fileName = fileName+"贵州特有物种名录";
                content = getContent( fileName,diversityReportRepository.getAnimaisByKingdom5( judgeIds( areaIds ) ) );
                break;
            case "6":
                fileName = fileName+"地方特有物种名录";
                content = getContent( fileName,diversityReportRepository.getAnimaisByKingdom6( judgeIds( areaIds ) ) );
                break;
            case "7":
                fileName = fileName+"IUCN物种红色名录";
                ids = diversityReportRepository.getAnimaisByKingdom7();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom1( judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "8":
                fileName = fileName+"中国生物多样性红色名录";
                ids = diversityReportRepository.getAnimaisByKingdom8();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom1( judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "9":
                fileName = fileName+"濒危野生动植物国际贸易公约（CITES）名录";
                ids = diversityReportRepository.getAnimaisByKingdom9();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom1( judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "10":
                fileName = fileName+"国家I级重点保护野生动物名录";
                List<Long> animalIds = diversityReportRepository.getAnimaisByKingdom1();
                ids = diversityReportRepository.getAnimaisByKingdom10();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom2( judgeIds( animalIds ),judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "11":
                fileName = fileName+"国家II级重点保护野生动物名录";
                List<Long> animalId = diversityReportRepository.getAnimaisByKingdom1();
                ids = diversityReportRepository.getAnimaisByKingdom11();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom2( judgeIds( animalId ),judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "12":
                fileName = fileName+"国家I级重点保护野生植物名录";
                List<Long> plantIds = diversityReportRepository.getAnimaisByKingdom2();
                ids = diversityReportRepository.getAnimaisByKingdom10();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom2( judgeIds( plantIds ),judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            case "13":
                fileName = fileName+"国家II级重点保护野生植物名录";
                List<Long> plantId = diversityReportRepository.getAnimaisByKingdom2();
                ids = diversityReportRepository.getAnimaisByKingdom11();
                content = getContent( fileName,diversityReportRepository.getNameAndLatinByKingdom2( judgeIds( plantId ),judgeIds( areaIds ),judgeIds( ids ) ) );
                break;
            default: break;
        }
        list.add( fileName);
        list.add( content );
        return list;
    }

    @Override
    public List getProtection() {
        return distributionRepository.getProtection();
    }

    @Override
    public List getList1(String title,String creator, Pageable pageable1) {
        List list = new ArrayList(  );
        list.add( diversityReportRepository.getCountByTitle1(title,creator) );
        list.add( diversityReportRepository.getAllListByTitle1(title,creator,pageable1) );
        return list;
    }

    @Override
    public String findTitleById(Long id) {
        return diversityReportRepository.findTitleById(id);
    }

    /**
     * 判断id集合是否为空
     * @param ids
     * @return
     */
    public List<Long> judgeIds(List<Long> ids){
        if(ids.size()>0){
            return ids;
        }
        return null;
    }

    /**
     * 获取附件内容
     * @param title
     * @param objects
     * @return
     */
    public String getContent(String title,List<Object> objects){
        String content = "<h2>"+title+"</h2><br>";
        if(objects.size()<=0){
            return content;
        }
        for (Object o:objects){
            Object[] ob = (Object[]) o;
            content = content + ob[0]+" "+ob[1]+"<br>";
        }
        return content;
    }

    /**
     * 替换内容
     * @param content
     * @param provinceIds
     * @param areaIds
     * @return
     */
    public String testWordContent(String content, List<Long> provinceIds, List<Long> areaIds,String wetland,String weland){
        List<Replace> list = new ArrayList <>();
        // todo styareaWetlandPCT 需要加载，空着
        list.add( new Replace( "styareaWetlandPCT",getPCT2(wetland,weland) ) );
        //获取洞穴生物界、门、纲、目、科、属、种的数量
        Object[] object = (Object[])diversityReportRepository.findByHabitatAndArea("洞穴",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "stycaveCreatureNum1",""+object[0] ) );
        list.add( new Replace( "stycaveCreatureNum2",""+object[1] ) );
        list.add( new Replace( "stycaveCreatureNum3",""+object[2] ) );
        list.add( new Replace( "stycaveCreatureNum4",""+object[3] ) );
        list.add( new Replace( "stycaveCreatureNum5",""+object[4] ) );
        list.add( new Replace( "stycaveCreatureNum6",""+object[5] ) );
        list.add( new Replace( "stycaveCreatureNum7",""+object[6] ) );
        //获取中国特有种
        List<Object> objectList = organismRepository.findByHabitatAndAreaAndPeculiar("洞穴","中国特有",areaIds.size()>0?areaIds:null);
        //获取贵州特有种
        List<Object> objectList1 = organismRepository.findByHabitatAndAreaAndPeculiar("洞穴","贵州狭域分布",areaIds.size()>0?areaIds:null);
        //获取地方特有种
        List<Object> objectList2 = organismRepository.findByHabitatAndAreaAndPeculiar("洞穴","地方特有",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "stycaveEndemicSpeciesNum1",""+objectList.size()));
        list.add( new Replace( "stycaveEndemicSpeciesNum2",""+objectList1.size()));
        list.add( new Replace( "stycaveEndemicSpeciesNum3",""+objectList2.size()));

        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stycaveEndemicSpecies1",getSpecies(objectList)));
        //贵州特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stycaveEndemicSpecies2",getSpecies(objectList1)));
        //地方特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stycaveEndemicSpecies3",getSpecies(objectList2)));

        //获取指定地区下面的界，门，纲，目，科，属，种数量
        Object[] objects = (Object[]) diversityReportRepository.getCountByArea(areaIds.size()>0?areaIds:null);
        list.add( new Replace( "stylivingSpeciesNum1",""+objects[0] ) );
        list.add( new Replace( "stylivingSpeciesNum2",""+objects[1] ) );
        list.add( new Replace( "stylivingSpeciesNum3",""+objects[2] ) );
        list.add( new Replace( "stylivingSpeciesNum4",""+objects[3] ) );
        list.add( new Replace( "stylivingSpeciesNum5",""+objects[4] ) );
        list.add( new Replace( "stylivingSpeciesNum6",""+objects[5] ) );
        list.add( new Replace( "stylivingSpeciesNum7",""+objects[6] ) );
        //获取界下的门，纲，目，科，属，种数量
        Object[] kingdomObject = (Object[]) diversityReportRepository.getCountByKingdomAndArea("动物界",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "styanimalNum1",""+kingdomObject[0] ) );
        list.add( new Replace( "styanimalNum2",""+kingdomObject[1] ) );
        list.add( new Replace( "styanimalNum3",""+kingdomObject[2] ) );
        list.add( new Replace( "styanimalNum4",""+kingdomObject[3] ) );
        list.add( new Replace( "styanimalNum5",""+kingdomObject[4] ) );
        list.add( new Replace( "styanimalNum6",""+kingdomObject[5] ) );
        //获取贵州省下哺乳动物目、科、属、种的数量
        Object[] kingdomObject1 = (Object[]) diversityReportRepository.getCountByClassAndArea("哺乳",provinceIds.size()>0?provinceIds:null);
        list.add( new Replace( "stymammalNum1",""+kingdomObject1[0] ) );
        list.add( new Replace( "stymammalNum2",""+kingdomObject1[1] ) );
        list.add( new Replace( "stymammalNum3",""+kingdomObject1[2] ) );
        list.add( new Replace( "stymammalNum4",""+kingdomObject1[3] ) );
        //获取指定地区下哺乳动物目、科、属、种的数量
        Object[] kingdomObject2 = (Object[]) diversityReportRepository.getCountByClassAndArea("哺乳",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "styareaMammalNum1",""+kingdomObject2[0] ) );
        list.add( new Replace( "styareaMammalNum2",""+kingdomObject2[1] ) );
        list.add( new Replace( "styareaMammalNum3",""+kingdomObject2[2] ) );
        list.add( new Replace( "styareaMammalNum4",""+kingdomObject2[3] ) );

        //世界哺乳动物总种数比例
        list.add( new Replace( "styareaMammalPCT1",getPCT2(kingdomObject2[3],5488 )) );
        //中国哺乳动物总种数比例
        list.add( new Replace( "styareaMammalPCT2",getPCT2(kingdomObject2[3],673 ) ) );
        //贵州哺乳动物总种数比例
        list.add( new Replace( "styareaMammalPCT3",getPCT2(kingdomObject2[3],kingdomObject1[3]  ) ) );

        //国家重点保护野生动物种类
        List<Long> idsst = taxonomyRepository.getIdByTClass("哺乳纲",areaIds.size()>0?areaIds:null);
        idsst= idsst.size()>0?idsst:null;
       Integer counts1 = conservationStatusRepository.getCount("国家重点保护野生动物","I级",idsst);
       List<Long> ids1 = conservationStatusRepository.getIds("国家重点保护野生动物","I级", idsst);
        ids1 = ids1.size()>0?ids1:null;
       Integer counts2 = conservationStatusRepository.getCount("国家重点保护野生动物","II级", idsst);
        List<Long> ids2 = conservationStatusRepository.getIds("国家重点保护野生动物","II级", idsst);
        ids2 = ids2.size()>0?ids2:null;
        list.add( new Replace( "stymammalSpeciesNum1",""+counts1 ) );
        list.add( new Replace( "stymammalSpeciesNum2",""+counts2 ) );
        //获取I级国家重点保护野生动物
        List<Object> objectList3 = organismRepository.getOrganismByIds(ids1);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stymammalSpecies1",getSpecies(objectList3)));

       //获取II级国家重点保护野生动物
        List<Object> objectList4 = organismRepository.getOrganismByIds(ids2);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stymammalSpecies2",getSpecies(objectList4)));


        //IUCN物种红色名录
        Integer count = conservationStatusRepository.getCount("IUCN物种红色名录","濒危（EN）",idsst);
        Integer count01 = conservationStatusRepository.getCount("IUCN物种红色名录","易危",idsst);
        Integer count02 = conservationStatusRepository.getCount("IUCN物种红色名录","近危",idsst);
        Integer count03= conservationStatusRepository.getCount("IUCN物种红色名录","低危",idsst);
        Integer count04 = conservationStatusRepository.getCount("IUCN物种红色名录","数据缺乏",idsst);

        list.add( new Replace( "stymammalEndangeredCategory1",""+count ) );
        list.add( new Replace( "stymammalEndangeredCategory2",""+count01 ) );
        list.add( new Replace( "stymammalEndangeredCategory3",""+count02 ) );
        list.add( new Replace( "stymammalEndangeredCategory4",""+count03 ) );
        list.add( new Replace( "stymammalEndangeredCategory5",""+count04 ) );

        //中国生物多样性红色名录（脊椎动物）濒危等级
        Integer data = conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危",idsst);
        Integer data1 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危",idsst);
        Integer data2 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危",idsst);
        Integer data3 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危",idsst);
        Integer data4 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","无危",idsst);
        Integer data5 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏",idsst);
        list.add( new Replace( "stymammalChinaEndangeredCategory1",""+data ) );
        list.add( new Replace( "stymammalChinaEndangeredCategory2",""+data1 ) );
        list.add( new Replace( "stymammalChinaEndangeredCategory3",""+data2 ) );
        list.add( new Replace( "stymammalChinaEndangeredCategory4",""+data3 ) );
        list.add( new Replace( "stymammalChinaEndangeredCategory5",""+data4 ) );
        list.add( new Replace( "stymammalChinaEndangeredCategory6",""+data5 ) );

        //濒危野生动植物种国际贸易公约
        Integer data01 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录I",idsst);
        Integer data02 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录II",idsst);
        Integer data03 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录III",idsst);
        list.add( new Replace( "stymammalEndangeredCITES1",""+data01 ) );
        list.add( new Replace( "stymammalEndangeredCITES2",""+data02 ) );
        list.add( new Replace( "stymammalEndangeredCITES3",""+data03 ) );

        //特有种情况
        List<Object> objectList5 =  organismRepository.getOrganismByEndemismAndIds("中国特有",idsst);
        List<Object> objectList6 =  organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",idsst);
        List<Object> objectList7 =  organismRepository.getOrganismByEndemismAndIds("贵州地方特有",idsst);
        List<Object> objectList8 =  organismRepository.getOrganismByEndemismAndIds("|外来",idsst);

        list.add( new Replace( "stymammalEndemicSpeciesNum1",""+objectList5.size() ) );
        list.add( new Replace( "stymammalEndemicSpeciesNum2",""+objectList6.size() ) );
        list.add( new Replace( "stymammalEndemicSpeciesNum3",""+objectList7.size() ) );
        list.add( new Replace( "stymammalAlienSpeciesNum",""+objectList8.size() ) );
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stymammalEndemicSpecies1",getSpecies(objectList5)));
        //贵州特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stymammalEndemicSpecies2",getSpecies(objectList6)));
        //地方特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stymammalEndemicSpecies3",getSpecies(objectList7)));
        //外来物种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "stymammalAlienSpecies",getSpecies(objectList8)));

        //以下两栖纲
        //根据贵州省获取两栖纲目、科、属、种的数量
        Object[] objects1 = (Object[]) diversityReportRepository.getCountByClassAndArea("两栖纲",provinceIds.size()>0?provinceIds:null);
        list.add( new Replace( "styamphibianNum1",""+objects1[0] ) );
        list.add( new Replace( "styamphibianNum2",""+objects1[1] ) );
        list.add( new Replace( "styamphibianNum3",""+objects1[2] ) );
        list.add( new Replace( "styamphibianNum4",""+objects1[3] ) );

        //获取指定地区下两栖纲目、科、属、种的数量
        Object[] objects2 = (Object[]) diversityReportRepository.getCountByClassAndArea("两栖纲",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "styareaAmphibianNum1",""+objects2[0] ) );
        list.add( new Replace( "styareaAmphibianNum2",""+objects2[1] ) );
        list.add( new Replace( "styareaAmphibianNum3",""+objects2[2] ) );
        list.add( new Replace( "styareaAmphibianNum4",""+objects2[3] ) );

        //世界哺乳纲总种数比例
        list.add( new Replace( "styareaAmphibianPCT1",getPCT2(objects2[3],5448) ) );
        //中国哺乳纲总种数比例
        list.add( new Replace( "styareaAmphibianPCT2",getPCT2(objects2[3],673) ) );
        //贵州哺乳纲总种数比例
        list.add( new Replace( "styareaAmphibianPCT3",getPCT2(objects2[3],objects1[3])) );

        //国家两栖纲重点保护野生动物种类
        List<Long> countsq=taxonomyRepository.getIdByTClass("两栖纲",areaIds.size()>0?areaIds:null);
        countsq =countsq.size()>0?countsq:null;
        Integer countss1 = conservationStatusRepository.getCount("国家重点保护野生动物","I级", countsq);
        List<Long> idss1 = conservationStatusRepository.getIds("国家重点保护野生动物","I级", countsq);
        idss1 = idss1.size()>0?idss1:null;
        Integer countss2 = conservationStatusRepository.getCount("国家重点保护野生动物","II级", countsq);
        List<Long> idss2 = conservationStatusRepository.getIds("国家重点保护野生动物","II级", countsq);
        idss2 = idss2.size()>0?idss2:null;
        list.add( new Replace( "styamphibianSpeciesNum1",""+countss1 ) );
        list.add( new Replace( "styamphibianSpeciesNum2",""+countss2 ) );
        //获取I级国家重点保护野生动物
        List<Object> objectLists3 = organismRepository.getOrganismByIds(idss1);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styamphibianSpecies1",getSpecies(objectLists3)));
        //获取I级国家重点保护野生动物
        List<Object> objectLists4 = organismRepository.getOrganismByIds(idss2);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styamphibianSpecies2",getSpecies(objectLists4)));


        //IUCN物种红色名录
        Integer counts = conservationStatusRepository.getCount("IUCN物种红色名录","濒危（EN）",countsq);
        Integer counts01 = conservationStatusRepository.getCount("IUCN物种红色名录","易危",countsq);
        Integer counts02 = conservationStatusRepository.getCount("IUCN物种红色名录","近危",countsq);
        Integer counts03= conservationStatusRepository.getCount("IUCN物种红色名录","低危",countsq);
        Integer counts04 = conservationStatusRepository.getCount("IUCN物种红色名录","数据缺乏",countsq);

        list.add( new Replace( "styamphibianEndangeredCategory1",""+counts ) );
        list.add( new Replace( "styamphibianEndangeredCategory2",""+counts01 ) );
        list.add( new Replace( "styamphibianEndangeredCategory3",""+counts02 ) );
        list.add( new Replace( "styamphibianEndangeredCategory4",""+counts03 ) );
        list.add( new Replace( "styamphibianEndangeredCategory5",""+counts04 ) );

        //获取两栖动物中国生物多样性红色名录濒危等级
        Integer datas = conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危",countsq);
        Integer datas1 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危",countsq);
        Integer datas2 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危",countsq);
        Integer datas3 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危",countsq);
        Integer datas4 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","无危",countsq);
        Integer datas5 = conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏",countsq);
        list.add( new Replace( "styamphibianChinaEndangeredCategory1",""+datas ) );
        list.add( new Replace( "styamphibianChinaEndangeredCategory2",""+datas1 ) );
        list.add( new Replace( "styamphibianChinaEndangeredCategory3",""+datas2 ) );
        list.add( new Replace( "styamphibianChinaEndangeredCategory4",""+datas3 ) );
        list.add( new Replace( "styamphibianChinaEndangeredCategory5",""+datas4 ) );
        list.add( new Replace( "styamphibianChinaEndangeredCategory6",""+datas5 ) );

        //濒危野生动植物种国际贸易公约
        Integer datas01 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录I",countsq);
        Integer datas02 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录II",countsq);
        Integer datas03 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录III",countsq);
        list.add( new Replace( "styamphibianEndangeredCITES1",""+datas01 ) );
        list.add( new Replace( "styamphibianEndangeredCITES2",""+datas02 ) );
        list.add( new Replace( "styamphibianEndangeredCITES3",""+datas03 ) );

        //两栖纲特有种情况
        List<Object> objectLists5 =  organismRepository.getOrganismByEndemismAndIds("中国特有",countsq);
        List<Object> objectLists6 =  organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",countsq);
        List<Object> objectLists7 =  organismRepository.getOrganismByEndemismAndIds("贵州地方特有",countsq);
        List<Object> objectLists8 =  organismRepository.getOrganismByEndemismAndIds("|外来",countsq);

        list.add( new Replace( "styamphibianEndemicSpeciesNum1",""+objectLists5.size() ) );
        list.add( new Replace( "styamphibianEndemicSpeciesNum2",""+objectLists6.size() ) );
        list.add( new Replace( "styamphibianEndemicSpeciesNum3",""+objectLists7.size() ) );
        list.add( new Replace( "styamphibianAlienSpeciesNum",""+objectLists8.size() ) );

        //获取两栖纲中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styamphibianEndemicSpecies1",getSpecies(objectLists5)));
        //获取两栖纲贵州特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styamphibianEndemicSpecies2",getSpecies(objectLists6)));

        //获取两栖纲地方特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styamphibianEndemicSpecies3",getSpecies(objectLists7)));

        //获取两栖纲外来物种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styamphibianAlienSpecies",getSpecies(objectLists8)));

        //以下是爬行纲
        //根据贵州省获取爬行纲目、科、属、种的数量
        Object[] objectss1 = (Object[]) diversityReportRepository.getCountByClassAndArea("爬行纲",provinceIds.size()>0?provinceIds:null);
        list.add( new Replace( "styreptileNum1",""+objectss1[0] ) );
        list.add( new Replace( "styreptileNum2",""+objectss1[1] ) );
        list.add( new Replace( "styreptileNum3",""+objectss1[2] ) );
        list.add( new Replace( "styreptileNum4",""+objectss1[3] ) );

        //获取指定地区下两栖纲目、科、属、种的数量
        Object[] objectss2 = (Object[]) diversityReportRepository.getCountByClassAndArea("爬行纲",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "styareaReptileNum1",""+objectss2[0] ) );
        list.add( new Replace( "styareaReptileNum2",""+objectss2[1] ) );
        list.add( new Replace( "styareaReptileNum3",""+objectss2[2] ) );
        list.add( new Replace( "styareaReptileNum4",""+objectss2[3] ) );

        list.add( new Replace( "styareaReptilePCT1",getPCT2(objectss2[3],5488) ) );
        list.add( new Replace( "styareaReptilePCT2",getPCT2(objectss2[3],673) ) );
        list.add( new Replace( "styareaReptilePCT3",getPCT2(objectss2[3],objectss1[3]) ) );

        List<Long> ids = taxonomyRepository.getIdByTClass("爬行纲",areaIds.size()>0?areaIds:null);
        ids = ids.size()>0?ids:null;
        //国家爬行纲重点保护野生动物种类
        Integer countss11 = conservationStatusRepository.getCount("国家重点保护野生动物","I级",ids );
        List<Long> idss11 = conservationStatusRepository.getIds("国家重点保护野生动物","I级", ids);
        idss11 = idss11.size()>0?idss11:null;
        Integer countss12 = conservationStatusRepository.getCount("国家重点保护野生动物","II级", ids);
        List<Long> idss12 = conservationStatusRepository.getIds("国家重点保护野生动物","II级",ids);
        idss12 = idss12.size()>0?idss12:null;
        list.add( new Replace( "styreptileSpeciesNum1",""+countss11 ) );
        list.add( new Replace( "styreptileSpeciesNum2",""+countss12 ) );
        //获取I级国家重点保护野生动物
        List<Object> objectLists13 = organismRepository.getOrganismByIds(idss11);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styreptileSpecies1",getSpecies(objectLists13)));

        //获取I级国家重点保护野生动物
        List<Object> objectLists14 = organismRepository.getOrganismByIds(idss12);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styreptileSpecies2",getSpecies(objectLists14)));

        //IUCN物种红色名录
        Integer countos = conservationStatusRepository.getCount("IUCN物种红色名录","濒危（EN）",ids);
        Integer countso01 = conservationStatusRepository.getCount("IUCN物种红色名录","易危",ids);
        Integer countso02 = conservationStatusRepository.getCount("IUCN物种红色名录","近危",ids);
        Integer countso03= conservationStatusRepository.getCount("IUCN物种红色名录","低危",ids);
        Integer countso04 = conservationStatusRepository.getCount("IUCN物种红色名录","数据缺乏",ids);

        list.add( new Replace( "styreptileEndangeredCategory1",""+countos ) );
        list.add( new Replace( "styreptileEndangeredCategory2",""+countso01 ) );
        list.add( new Replace( "styreptileEndangeredCategory3",""+countso02 ) );
        list.add( new Replace( "styreptileEndangeredCategory4",""+countso03 ) );
        list.add( new Replace( "styreptileEndangeredCategory5",""+countso04 ) );

        //获取两栖动物中国生物多样性红色名录濒危等级
        Integer data1s = conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危",ids);
        Integer data11s = conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危",ids);
        Integer data12s = conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危",ids);
        Integer datas13s = conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危",ids);
        Integer datas14s = conservationStatusRepository.getCount("中国生物多样性红色名录等级","无危",ids);
        Integer datas15s = conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏",ids);
        list.add( new Replace( "styreptileChinaEndangeredCategory1",""+data1s ) );
        list.add( new Replace( "styreptileChinaEndangeredCategory2",""+data11s ) );
        list.add( new Replace( "styreptileChinaEndangeredCategory3",""+data12s ) );
        list.add( new Replace( "styreptileChinaEndangeredCategory4",""+datas13s ) );
        list.add( new Replace( "styreptileChinaEndangeredCategory5",""+datas14s ) );
        list.add( new Replace( "styreptileChinaEndangeredCategory6",""+datas15s ) );

        //濒危野生动植物种国际贸易公约
        Integer datass01 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录I",ids);
        Integer datass02 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录II",ids);
        Integer datass03 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录III",ids);
        list.add( new Replace( "styreptileEndangeredCITES1",""+datass01 ) );
        list.add( new Replace( "styreptileEndangeredCITES2",""+datass02 ) );
        list.add( new Replace( "styreptileEndangeredCITES3",""+datass03 ) );

        //爬行纲特有种情况
        List<Object> objectListss5 =  organismRepository.getOrganismByEndemismAndIds("中国特有",ids);
        List<Object> objectListss6 =  organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",ids);
        List<Object> objectListss7 =  organismRepository.getOrganismByEndemismAndIds("贵州地方特有",ids);
        List<Object> objectListss8 =  organismRepository.getOrganismByEndemismAndIds("|外来",ids);

        list.add( new Replace( "styreptileEndemicSpeciesNum1",""+objectListss5.size() ) );
        list.add( new Replace( "styreptileEndemicSpeciesNum2",""+objectListss6.size() ) );
        list.add( new Replace( "styreptileEndemicSpeciesNum3",""+objectListss7.size() ) );
        list.add( new Replace( "styreptileAlienSpeciesNum",""+objectListss8.size() ) );

        //获取爬行纲中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styreptileEndemicSpecies1",getSpecies(objectListss5)));
        //获取爬行纲贵州特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styreptileEndemicSpecies2",getSpecies(objectListss6)));
        //获取爬行纲地方特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styreptileEndemicSpecies3",getSpecies(objectListss7)));
        //获取爬行纲外来物种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styreptileAlienSpecies",getSpecies(objectListss8)));

        //以下是鱼纲
        //根据贵州省获取爬行纲目、科、属、种的数量
        Object[] objectess1 = (Object[]) diversityReportRepository.getCountByClassAndArea("鱼纲",provinceIds.size()>0?provinceIds:null);
        list.add( new Replace( "styfishNum1",""+objectess1[0] ) );
        list.add( new Replace( "styfishNum2",""+objectess1[1] ) );
        list.add( new Replace( "styfishNum3",""+objectess1[2] ) );
        list.add( new Replace( "styfishNum4",""+objectess1[3] ) );

        //获取指定地区下两栖纲目、科、属、种的数量
        Object[] object1ss2 = (Object[]) diversityReportRepository.getCountByClassAndArea("鱼纲",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "styareaFishNum1",""+object1ss2[0] ) );
        list.add( new Replace( "styareaFishNum2",""+object1ss2[1] ) );
        list.add( new Replace( "styareaFishNum3",""+object1ss2[2] ) );
        list.add( new Replace( "styareaFishNum4",""+object1ss2[3] ) );

        //世界哺乳纲总种数比例
        list.add( new Replace( "styareaFishPCT1",getPCT2(object1ss2[3],5488) ) );
        //中国哺乳纲总种数比例
        list.add( new Replace( "styareaFishPCT2",getPCT2(object1ss2[3],673) ) );
        //贵州哺乳纲总种数比例
        list.add( new Replace( "styareaFishPCT3",getPCT2(object1ss2[3],objectess1[3]) ) );

        //国家两栖纲重点保护野生动物种类
        List<Long> ids11 = taxonomyRepository.getIdByTClass("鱼纲",areaIds.size()>0?areaIds:null);
        ids11 = ids11.size()>0?ids11:null;
        Integer countess1 = conservationStatusRepository.getCount("国家重点保护野生动物","I级", ids11);
        List<Long> idess1 = conservationStatusRepository.getIds("国家重点保护野生动物","I级", ids11);
        idess1 = idess1.size()>0?idess1:null;
        Integer countess2 = conservationStatusRepository.getCount("国家重点保护野生动物","II级", ids11);
        List<Long> idess2 = conservationStatusRepository.getIds("国家重点保护野生动物","II级", ids11);
        idess2 = idess2.size()>0?idess2:null;
        list.add( new Replace( "styfishSpeciesNum1",""+countess1 ) );
        list.add( new Replace( "styfishSpeciesNum2",""+countess2 ) );
        //获取I级国家重点保护野生动物
        List<Object> objectListes3 = organismRepository.getOrganismByIds(idess1);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styfishSpecies1",getSpecies(objectListes3)));

        //获取II级国家重点保护野生动物
        List<Object> objectListes4 = organismRepository.getOrganismByIds(idess2);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styfishSpecies2",getSpecies(objectListes4)));

        //IUCN物种红色名录
        Integer countos1 = conservationStatusRepository.getCount("IUCN物种红色名录","濒危（EN）",ids11);
        Integer countso011 = conservationStatusRepository.getCount("IUCN物种红色名录","易危",ids11);
        Integer countso021 = conservationStatusRepository.getCount("IUCN物种红色名录","近危",ids11);
        Integer countso031= conservationStatusRepository.getCount("IUCN物种红色名录","低危",ids11);
        Integer countso041 = conservationStatusRepository.getCount("IUCN物种红色名录","数据缺乏",ids11);

        list.add( new Replace( "styfishEndangeredCategory1",""+countos1 ) );
        list.add( new Replace( "styfishEndangeredCategory2",""+countso011 ) );
        list.add( new Replace( "styfishEndangeredCategory3",""+countso021 ) );
        list.add( new Replace( "styfishEndangeredCategory4",""+countso031 ) );
        list.add( new Replace( "styfishEndangeredCategory5",""+countso041 ) );

        //获取两栖动物中国生物多样性红色名录濒危等级
        Integer data1se = conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危",ids11);
        Integer data11se = conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危",ids11);
        Integer data12se = conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危",ids11);
        Integer datas13se = conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危",ids11);
        Integer datas14se = conservationStatusRepository.getCount("中国生物多样性红色名录等级","无危",ids11);
        Integer datas15se = conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏",ids11);
        list.add( new Replace( "styfishChinaEndangeredCategory1",""+data1se ) );
        list.add( new Replace( "styfishChinaEndangeredCategory2",""+data11se ) );
        list.add( new Replace( "styfishChinaEndangeredCategory3",""+data12se ) );
        list.add( new Replace( "styfishChinaEndangeredCategory4",""+datas13se ) );
        list.add( new Replace( "styfishChinaEndangeredCategory5",""+datas14se ) );
        list.add( new Replace( "styfishChinaEndangeredCategory6",""+datas15se ) );

        //濒危野生动植物种国际贸易公约
        Integer datass011 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录I",ids11);
        Integer datass021 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录II",ids11);
        Integer datass031 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录III",ids11);
        list.add( new Replace( "styfishEndangeredCITES1",""+datass011 ) );
        list.add( new Replace( "styfishEndangeredCITES2",""+datass021 ) );
        list.add( new Replace( "styfishEndangeredCITES3",""+datass031 ) );

        //鱼纲特有种情况
        List<Object> objectListess5 =  organismRepository.getOrganismByEndemismAndIds("中国特有",ids11);
        List<Object> objectListess6 =  organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",ids11);
        List<Object> objectListess7 =  organismRepository.getOrganismByEndemismAndIds("贵州地方特有",ids11);
        List<Object> objectListess8 =  organismRepository.getOrganismByEndemismAndIds("|外来",ids11);

        list.add( new Replace( "styfishEndemicSpeciesNum1",""+objectListess5.size() ) );
        list.add( new Replace( "styfishEndemicSpeciesNum2",""+objectListess6.size() ) );
        list.add( new Replace( "styfishEndemicSpeciesNum3",""+objectListess7.size() ) );
        list.add( new Replace( "styfishAlienSpeciesNum",""+objectListess8.size() ) );

        //获取鱼纲中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styfishEndemicSpecies1",getSpecies(objectListess5)));

        //获取鱼纲贵州特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styfishEndemicSpecies2",getSpecies(objectListess6)));

        //获取鱼纲地方特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styfishEndemicSpecies3",getSpecies(objectListess7)));
        //获取鱼纲外来物种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styfishAlienSpecies",getSpecies(objectListess8)));

        //以下是昆虫纲
        //根据贵州省获取爬行纲目、科、属、种的数量
        Object[] objectess11 = (Object[]) diversityReportRepository.getCountByClassAndArea("昆虫纲",provinceIds.size()>0?provinceIds:null);
        list.add( new Replace( "styinsectaNum1",""+objectess11[0] ) );
        list.add( new Replace( "styinsectaNum2",""+objectess11[1] ) );
        list.add( new Replace( "styinsectaNum3",""+objectess11[2] ) );
        list.add( new Replace( "styinsectaNum4",""+objectess11[3] ) );

        //获取指定地区下两栖纲目、科、属、种的数量
        Object[] object1ess2 = (Object[]) diversityReportRepository.getCountByClassAndArea("昆虫纲",areaIds.size()>0?areaIds:null);
        list.add( new Replace( "styareaInsectaNum1",""+object1ess2[0] ) );
        list.add( new Replace( "styareaInsectaNum2",""+object1ess2[1] ) );
        list.add( new Replace( "styareaInsectaNum3",""+object1ess2[2] ) );
        list.add( new Replace( "styareaInsectaNum4",""+object1ess2[3] ) );


        list.add( new Replace( "styareaInsectaPCT1",getPCT2(object1ess2[3],5488) ) );
        list.add( new Replace( "styareaInsectaPCT2",getPCT2(object1ess2[3],51000)) );
        list.add( new Replace( "styareaInsectaPCT3",getPCT2(object1ess2[3],objectess11[3]) ) );

        //国家两栖纲重点保护野生动物种类
        List<Long> ids111 = taxonomyRepository.getIdByTClass("昆虫纲",areaIds.size()>0?areaIds:null);
        ids111 = ids111.size()>0?ids111:null;
        Integer countess11 = conservationStatusRepository.getCount("国家重点保护野生动物","I级", ids111);
        List<Long> idess11 = conservationStatusRepository.getIds("国家重点保护野生动物","I级", ids111);
        idess11 = idess11.size()>0?idess11:null;
        Integer countess21 = conservationStatusRepository.getCount("国家重点保护野生动物","II级", ids111);
        List<Long> idess21 = conservationStatusRepository.getIds("国家重点保护野生动物","II级", ids111);
        idess21 = idess21.size()>0?idess21:null;
        list.add( new Replace( "styinsectaSpeciesNum1",""+countess11 ) );
        list.add( new Replace( "styinsectaSpeciesNum2",""+countess21 ) );
        //获取I级国家重点保护野生动物
        List<Object> objectListese3 = organismRepository.getOrganismByIds(idess11);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styinsectaSpecies1",getSpecies(objectListese3)));

        //获取I级国家重点保护野生动物
        List<Object> objectListese4 = organismRepository.getOrganismByIds(idess21);
        //中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styinsectaSpecies2",getSpecies(objectListese4)));

        //IUCN物种红色名录
        Integer counteos1 = conservationStatusRepository.getCount("IUCN物种红色名录","濒危（EN）",ids111);
        Integer counteso011 = conservationStatusRepository.getCount("IUCN物种红色名录","易危",ids111);
        Integer counteso021 = conservationStatusRepository.getCount("IUCN物种红色名录","近危",ids111);
        Integer counteso031= conservationStatusRepository.getCount("IUCN物种红色名录","低危",ids111);
        Integer counteso041 = conservationStatusRepository.getCount("IUCN物种红色名录","数据缺乏",ids111);

        list.add( new Replace( "styinsectaEndangeredCategory1",""+counteos1 ) );
        list.add( new Replace( "styinsectaEndangeredCategory2",""+counteso011 ) );
        list.add( new Replace( "styinsectaEndangeredCategory3",""+counteso021 ) );
        list.add( new Replace( "styinsectaEndangeredCategory4",""+counteso031 ) );
        list.add( new Replace( "styinsectaEndangeredCategory5",""+counteso041 ) );

        //获取昆虫纲中国生物多样性红色名录濒危等级
        Integer data1ses = conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危",ids111);
        Integer data11ses = conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危",ids111);
        Integer data12ses = conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危",ids111);
        Integer datas13ses = conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危",ids111);
        Integer datas14ses = conservationStatusRepository.getCount("中国生物多样性红色名录等级","无危",ids111);
        Integer datas15ses = conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏",ids111);
        list.add( new Replace( "styinsectaChinaEndangeredCategory1",""+data1ses ) );
        list.add( new Replace( "styinsectaChinaEndangeredCategory2",""+data11ses ) );
        list.add( new Replace( "styinsectaChinaEndangeredCategory3",""+data12ses ) );
        list.add( new Replace( "styinsectaChinaEndangeredCategory4",""+datas13ses ) );
        list.add( new Replace( "styinsectaChinaEndangeredCategory5",""+datas14ses ) );
        list.add( new Replace( "styinsectaChinaEndangeredCategory6",""+datas15ses ) );

        //濒危野生动植物种国际贸易公约
        Integer datasse011 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录I",ids111);
        Integer datasse021 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录II",ids111);
        Integer datasse031 = conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约","附录III",ids111);
        list.add( new Replace( "styinsectaEndangeredCITES1",""+datasse011 ) );
        list.add( new Replace( "styinsectaEndangeredCITES2",""+datasse021 ) );
        list.add( new Replace( "styinsectaEndangeredCITES3",""+datasse031 ) );

        //鱼纲特有种情况
        List<Object> objectListesse5 =  organismRepository.getOrganismByEndemismAndIds("中国特有",ids111);
        List<Object> objectListesse6 =  organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",ids111);
        List<Object> objectListesse7 =  organismRepository.getOrganismByEndemismAndIds("贵州地方特有",ids111);
        List<Object> objectListesse8 =  organismRepository.getOrganismByEndemismAndIds("|外来",ids111);

        list.add( new Replace( "styinsectaEndemicSpeciesNum1",""+objectListesse5.size() ) );
        list.add( new Replace( "styinsectaEndemicSpeciesNum2",""+objectListesse6.size() ) );
        list.add( new Replace( "styinsectaEndemicSpeciesNum3",""+objectListesse7.size() ) );
        list.add( new Replace( "styinsectaAlienSpeciesNum",""+objectListesse8.size() ) );

        //获取鱼纲中国特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styinsectaEndemicSpecies1",getSpecies(objectListesse5)));
        //获取鱼纲贵州特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styinsectaEndemicSpecies2",getSpecies(objectListesse6)));
        //获取鱼纲地方特有种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styinsectaEndemicSpecies3",getSpecies(objectListesse7)));
        //获取鱼纲外来物种对应物种信息(名字、拉丁文名)
        list.add( new Replace( "styinsectaAlienSpecies",getSpecies(objectListesse8)));
        for(Replace replaceAll:list){
            content = content.replaceAll( replaceAll.getWordName(),replaceAll.getNewData() );
        }

        return content;
    }

    /**
     * 替换第二部分的文本内容
     * @param content   从文本中读取的文本内容
     * @param provinceIds  通过省查询的物种id集合
     * @param areaIds  通过选择地区查询的物种id集合
     * @return
     */
    public String getContent2(String content, List<Long> provinceIds, List<Long> areaIds){
        provinceIds = provinceIds.size()>0?provinceIds:null;
        areaIds = areaIds.size()>0?areaIds:null;
        List<Replace> list = new ArrayList <>(  );
        Object[] styquilt = (Object[]) diversityReportRepository.getCountByPhylumnAndArea( "被子植物门", areaIds);
        Integer integer1 = diversityReportRepository.getSeed1( "被子植物门",provinceIds );
        Object[] styfern = (Object[]) diversityReportRepository.getCountByPhylumnAndArea( "蕨类", areaIds);
        Integer integer2 = diversityReportRepository.getSeed1( "蕨类",provinceIds );
        Object[] stynakedSeed = (Object[]) diversityReportRepository.getCountByPhylumnAndArea( "裸子植物门", areaIds);
        Integer integer3 = diversityReportRepository.getSeed1( "裸子植物门",provinceIds );
        //维管束植物
        Integer[] stycaulineBundle = new Integer[3];
        for (int i = 0;i<3;i++){
            stycaulineBundle[i] = Integer.parseInt( ""+styquilt[i+2] )+Integer.parseInt( ""+styfern[i+2] )+Integer.parseInt( ""+stynakedSeed[i+2] );
        }
        String v = getPCT1(stycaulineBundle[2],integer1+integer2+integer3  );
        String v1 = getPCT1(  styquilt[4],integer1 );
        String v2 = getPCT1(  stynakedSeed[4],integer3 );
        String v3 = getPCT1(  styfern[4],integer2 );

        list.add( new Replace( "stycaulineBundle1",""+stycaulineBundle[0] ) );
        list.add( new Replace( "stycaulineBundle2",""+stycaulineBundle[1] ) );
        list.add( new Replace( "stycaulineBundle3",""+stycaulineBundle[2] ) );
        list.add( new Replace( "stycaulineBundle4",v ) );

        list.add( new Replace( "styfern1",""+styfern[2] ) );
        list.add( new Replace( "styfern2",""+styfern[3] ) );
        list.add( new Replace( "styfern3",""+styfern[4] ) );
        list.add( new Replace( "styfern4",v3 ) );

        list.add( new Replace( "stynakedSeed1",""+stynakedSeed[2] ) );
        list.add( new Replace( "stynakedSeed2",""+stynakedSeed[3] ) );
        list.add( new Replace( "stynakedSeed3",""+stynakedSeed[4] ) );
        list.add( new Replace( "stynakedSeed4",v2 ) );

        list.add( new Replace( "styquilt1",""+styquilt[2] ) );
        list.add( new Replace( "styquilt2",""+styquilt[3] ) );
        list.add( new Replace( "styquilt3",""+styquilt[4] ) );
        list.add( new Replace( "styquilt4",v1 ) );

        //大于100种的大科
        List<Object> bigFamilies = diversityReportRepository.getCountByKingdom("植物界",areaIds);

        String bigFamilie = "";
        if (bigFamilies.size()>0){
            bigFamilie = bigFamilie + "100种以上的大科有";
            int i = 0;
            for (Object o:bigFamilies){
                Object[] ob = (Object[]) o;
                if(i==0){
                    bigFamilie = bigFamilie + ob[0] +"("+ob[1]+"种)";
                    i++;
                }else {
                    bigFamilie = bigFamilie + "、"+ob[0] +"("+ob[1]+"种)";
                }
            }
            bigFamilie = bigFamilie + "。";
        }
        list.add( new Replace( "stybigFamilies",bigFamilie ) );

        //软体动物门
        Object[] stymolluscNum = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("软体动物门",provinceIds);
        list.add( new Replace( "stymolluscNum1",""+stymolluscNum[0] ) );
        list.add( new Replace( "stymolluscNum2",""+stymolluscNum[1] ) );
        list.add( new Replace( "stymolluscNum3",""+stymolluscNum[2] ) );
        list.add( new Replace( "stymolluscNum4",""+stymolluscNum[3] ) );
        list.add( new Replace( "stymolluscNum5",""+stymolluscNum[4] ) );

        Object[] styareaMolluscNum = (Object[]) diversityReportRepository.getCountByPhylumnAndArea( "软体动物门",areaIds );
        list.add( new Replace( "styareaMolluscNum1",""+styareaMolluscNum[0] ) );
        list.add( new Replace( "styareaMolluscNum2",""+styareaMolluscNum[1] ) );
        list.add( new Replace( "styareaMolluscNum3",""+styareaMolluscNum[2] ) );
        list.add( new Replace( "styareaMolluscNum4",""+styareaMolluscNum[3] ) );
        list.add( new Replace( "styareaMolluscNum5",""+styareaMolluscNum[4] ) );

        //地区软体动物门百分比计算
        list.add( new Replace( "styareaMolluscPCT1",getPCT2( styareaMolluscNum[4],5488 ) ) );
        list.add( new Replace( "styareaMolluscPCT2",getPCT2( styareaMolluscNum[4],673 )  ) );
        list.add( new Replace( "styareaMolluscPCT3",getPCT2( styareaMolluscNum[4], stymolluscNum[4] )  ) );

        //通过门筛选下来的物种id集合
        List<Long> stymolluscSpeciesNum = taxonomyRepository.getIdByPhylumn("软体动物门",areaIds);
        stymolluscSpeciesNum = stymolluscSpeciesNum.size()>0?stymolluscSpeciesNum:null;

        //国家重点保护野生动物种类
        Integer stymolluscSpeciesNum1 = conservationStatusRepository.getCount( "国家重点保护野生动植物等级","I级",stymolluscSpeciesNum);
        Integer stymolluscSpeciesNum2 = conservationStatusRepository.getCount( "国家重点保护野生动植物等级","II级",stymolluscSpeciesNum );
        List<Long> stymolluscSpecies1Ids = conservationStatusRepository.getIds( "国家重点保护野生动植物等级","I级",stymolluscSpeciesNum );
        List<Long> stymolluscSpecies2Ids = conservationStatusRepository.getIds( "国家重点保护野生动植物等级","II级",stymolluscSpeciesNum );
        list.add( new Replace( "stymolluscSpeciesNum1",""+ stymolluscSpeciesNum1 ) );
        list.add( new Replace( "stymolluscSpeciesNum2",""+ stymolluscSpeciesNum2 ) );
        list.add( new Replace( "stymolluscSpecies1",getSpecies( organismRepository.getOrganismByIds(stymolluscSpecies1Ids.size()>0?stymolluscSpecies1Ids:null) ) ) );
        list.add( new Replace( "stymolluscSpecies2",getSpecies( organismRepository.getOrganismByIds(stymolluscSpecies2Ids.size()>0?stymolluscSpecies2Ids:null)) ) );

        //IUCN 物种红色名录濒危等级
        list.add( new Replace( "stymolluscEndangeredCategory1",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","EN",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscEndangeredCategory2",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","VU",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscEndangeredCategory3",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","NT",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscEndangeredCategory4",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","LC",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscEndangeredCategory5",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","DD",stymolluscSpeciesNum ) ) );

        //中国生物多样性红色名录濒危等级
        list.add( new Replace( "stymolluscChinaEndangeredCategory1",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","CR",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscChinaEndangeredCategory2",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","EN",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscChinaEndangeredCategory3",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","VU",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscChinaEndangeredCategory4",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","NT",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscChinaEndangeredCategory5",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","LC",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscChinaEndangeredCategory6",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","DD",stymolluscSpeciesNum ) ) );

        //濒危野生动植物种国际贸易公约（CITES）种类
        list.add( new Replace( "stymolluscEndangeredCITES1",""+conservationStatusRepository.getCount( "濒危野生动植物种国际贸易公约(CITES) 等级","附录I",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscEndangeredCITES2",""+conservationStatusRepository.getCount( "濒危野生动植物种国际贸易公约(CITES) 等级","附录II",stymolluscSpeciesNum ) ) );
        list.add( new Replace( "stymolluscEndangeredCITES3",""+conservationStatusRepository.getCount( "濒危野生动植物种国际贸易公约(CITES) 等级","附录III",stymolluscSpeciesNum ) ) );

        //特有种情况
        List<Object> stymolluscEndemicSpecies1 = organismRepository.getOrganismByEndemismAndIds("中国特有",stymolluscSpeciesNum);
        List<Object> stymolluscEndemicSpecies2 = organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",stymolluscSpeciesNum);
        List<Object> stymolluscEndemicSpecies3 = organismRepository.getOrganismByEndemismAndIds("贵州地方特有",stymolluscSpeciesNum);
        list.add( new Replace( "stymolluscEndemicSpeciesNum1",""+stymolluscEndemicSpecies1.size() ) );
        list.add( new Replace( "stymolluscEndemicSpeciesNum2",""+stymolluscEndemicSpecies2.size() ) );
        list.add( new Replace( "stymolluscEndemicSpeciesNum3",""+stymolluscEndemicSpecies3.size() ) );
        list.add( new Replace( "stymolluscEndemicSpecies1",getSpecies( stymolluscEndemicSpecies1 ) ) );
        list.add( new Replace( "stymolluscEndemicSpecies2",getSpecies( stymolluscEndemicSpecies2 ) ) );
        list.add( new Replace( "stymolluscEndemicSpecies3",getSpecies( stymolluscEndemicSpecies3 ) ) );

        //外来物种情况
        List<Object> stymolluscAlienSpecies = organismRepository.getOrganismByEndemismAndIds("|外来",stymolluscSpeciesNum);
        list.add( new Replace( "stymolluscAlienSpeciesNum", ""+stymolluscAlienSpecies.size()) );
        list.add( new Replace( "stymolluscAlienSpecies",getSpecies( stymolluscAlienSpecies ) ) );


        //甲壳动物门
        Object[] stycrustaceanNum = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("甲壳动物门",provinceIds);
        list.add( new Replace( "stycrustaceanNum1",""+stycrustaceanNum[0] ) );
        list.add( new Replace( "stycrustaceanNum2",""+stycrustaceanNum[1] ) );
        list.add( new Replace( "stycrustaceanNum3",""+stycrustaceanNum[2] ) );
        list.add( new Replace( "stycrustaceanNum4",""+stycrustaceanNum[3] ) );
        list.add( new Replace( "stycrustaceanNum5",""+stycrustaceanNum[4] ) );

        Object[] styareaCrustaceanNum = (Object[]) diversityReportRepository.getCountByPhylumnAndArea( "甲壳动物门",areaIds );
        list.add( new Replace( "styareaCrustaceanNum1",""+styareaCrustaceanNum[0] ) );
        list.add( new Replace( "styareaCrustaceanNum2",""+styareaCrustaceanNum[1] ) );
        list.add( new Replace( "styareaCrustaceanNum3",""+styareaCrustaceanNum[2] ) );
        list.add( new Replace( "styareaCrustaceanNum4",""+styareaCrustaceanNum[3] ) );
        list.add( new Replace( "styareaCrustaceanNum5",""+styareaCrustaceanNum[4] ) );

        //地区甲壳动物门百分比计算
        list.add( new Replace( "styareaCrustaceanPCT1",getPCT2( styareaCrustaceanNum[4],5488 ) ) );
        list.add( new Replace( "styareaCrustaceanPCT2",getPCT2( styareaCrustaceanNum[4],673 )  ) );
        list.add( new Replace( "styareaCrustaceanPCT3",getPCT2( styareaCrustaceanNum[4], stycrustaceanNum[4] )  ) );

        //通过门筛选下来的物种id集合
        List<Long> stycrustaceanSpeciesNum = taxonomyRepository.getIdByPhylumn("甲壳动物门",areaIds);
        stycrustaceanSpeciesNum = stycrustaceanSpeciesNum.size()>0?stycrustaceanSpeciesNum:null;

        //国家重点保护野生动物种类
        Integer stycrustaceanSpeciesNum1 = conservationStatusRepository.getCount( "国家重点保护野生动植物等级","I级",stycrustaceanSpeciesNum);
        Integer stycrustaceanSpeciesNum2 = conservationStatusRepository.getCount( "国家重点保护野生动植物等级","II级",stycrustaceanSpeciesNum );
        List<Long> stycrustaceanSpecies1Ids = conservationStatusRepository.getIds( "国家重点保护野生动植物等级","I级",stycrustaceanSpeciesNum );
        List<Long> stycrustaceanSpecies2Ids = conservationStatusRepository.getIds( "国家重点保护野生动植物等级","II级",stycrustaceanSpeciesNum );
        list.add( new Replace( "stycrustaceanSpeciesNum1",""+ stycrustaceanSpeciesNum1 ) );
        list.add( new Replace( "stycrustaceanSpeciesNum2",""+ stycrustaceanSpeciesNum2 ) );
        list.add( new Replace( "stycrustaceanSpecies1",getSpecies( organismRepository.getOrganismByIds(stycrustaceanSpecies1Ids.size()>0?stycrustaceanSpecies1Ids:null) ) ) );
        list.add( new Replace( "stycrustaceanSpecies2",getSpecies( organismRepository.getOrganismByIds(stycrustaceanSpecies2Ids.size()>0?stycrustaceanSpecies2Ids:null)) ) );

        //IUCN 物种红色名录濒危等级
        list.add( new Replace( "stycrustaceanEndangeredCategory1",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","EN",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanEndangeredCategory2",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","VU",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanEndangeredCategory3",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","NT",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanEndangeredCategory4",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","LC",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanEndangeredCategory5",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","DD",stycrustaceanSpeciesNum ) ) );

        //中国生物多样性红色名录濒危等级
        list.add( new Replace( "stycrustaceanChinaEndangeredCategory1",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","CR",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanChinaEndangeredCategory2",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","EN",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanChinaEndangeredCategory3",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","VU",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanChinaEndangeredCategory4",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","NT",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanChinaEndangeredCategory5",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","LC",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanChinaEndangeredCategory6",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","DD",stycrustaceanSpeciesNum ) ) );

        //濒危野生动植物种国际贸易公约（CITES）种类
        list.add( new Replace( "stycrustaceanEndangeredCITES1",""+conservationStatusRepository.getCount( "濒危野生动植物种国际贸易公约(CITES) 等级","附录I",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanEndangeredCITES2",""+conservationStatusRepository.getCount( "濒危野生动植物种国际贸易公约(CITES) 等级","附录II",stycrustaceanSpeciesNum ) ) );
        list.add( new Replace( "stycrustaceanEndangeredCITES3",""+conservationStatusRepository.getCount( "濒危野生动植物种国际贸易公约(CITES) 等级","附录III",stycrustaceanSpeciesNum ) ) );

        //特有种情况
        List<Object> stycrustaceanEndemicSpecies1 = organismRepository.getOrganismByEndemismAndIds("中国特有",stycrustaceanSpeciesNum);
        List<Object> stycrustaceanEndemicSpecies2 = organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",stycrustaceanSpeciesNum);
        List<Object> stycrustaceanEndemicSpecies3 = organismRepository.getOrganismByEndemismAndIds("贵州地方特有",stycrustaceanSpeciesNum);
        list.add( new Replace( "stycrustaceanEndemicSpeciesNum1",""+stycrustaceanEndemicSpecies1.size() ) );
        list.add( new Replace( "stycrustaceanEndemicSpeciesNum2",""+stycrustaceanEndemicSpecies2.size() ) );
        list.add( new Replace( "stycrustaceanEndemicSpeciesNum3",""+stycrustaceanEndemicSpecies3.size() ) );
        list.add( new Replace( "stycrustaceanEndemicSpecies1",getSpecies( stycrustaceanEndemicSpecies1 ) ) );
        list.add( new Replace( "stycrustaceanEndemicSpecies2",getSpecies( stycrustaceanEndemicSpecies2 ) ) );
        list.add( new Replace( "stycrustaceanEndemicSpecies3",getSpecies( stycrustaceanEndemicSpecies3 ) ) );

        //外来物种情况
        List<Object> stycrustaceanAlienSpecies = organismRepository.getOrganismByEndemismAndIds("|外来",stycrustaceanSpeciesNum);
        list.add( new Replace( "stycrustaceanAlienSpeciesNum", ""+stycrustaceanAlienSpecies.size()) );
        list.add( new Replace( "stycrustaceanAlienSpecies",getSpecies( stycrustaceanAlienSpecies ) ) );


        //环节动物门
        Object[] styannelidsNum = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("环节动物门",provinceIds);
        list.add( new Replace( "styannelidsNum1",""+styannelidsNum[0] ) );
        list.add( new Replace( "styannelidsNum2",""+styannelidsNum[1] ) );
        list.add( new Replace( "styannelidsNum3",""+styannelidsNum[2] ) );
        list.add( new Replace( "styannelidsNum4",""+styannelidsNum[3] ) );
        list.add( new Replace( "styannelidsNum5",""+styannelidsNum[4] ) );

        Object[] styareaAnnelidsNum = (Object[]) diversityReportRepository.getCountByPhylumnAndArea( "环节动物门",areaIds );
        list.add( new Replace( "styareaAnnelidsNum1",""+styareaAnnelidsNum[0] ) );
        list.add( new Replace( "styareaAnnelidsNum2",""+styareaAnnelidsNum[1] ) );
        list.add( new Replace( "styareaAnnelidsNum3",""+styareaAnnelidsNum[2] ) );
        list.add( new Replace( "styareaAnnelidsNum4",""+styareaAnnelidsNum[3] ) );
        list.add( new Replace( "styareaAnnelidsNum5",""+styareaAnnelidsNum[4] ) );

        //地区环节动物门百分比计算
        list.add( new Replace( "styareaAnnelidsPCT1",getPCT2( styareaAnnelidsNum[4],5488 ) ) );
        list.add( new Replace( "styareaAnnelidsPCT2",getPCT2( styareaAnnelidsNum[4],673 )  ) );
        list.add( new Replace( "styareaAnnelidsPCT3",getPCT2( styareaAnnelidsNum[4], styannelidsNum[4] )  ) );

        //通过门筛选下来的物种id集合
        List<Long> styannelidsIds = taxonomyRepository.getIdByPhylumn("环节动物门",areaIds);
        styannelidsIds = styannelidsIds.size()>0?styannelidsIds:null;

        //IUCN 物种红色名录濒危等级
        list.add( new Replace( "styannelidsEndangeredCategory1",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","EN",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsEndangeredCategory2",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","VU",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsEndangeredCategory3",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","NT",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsEndangeredCategory4",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","LC",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsEndangeredCategory5",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","DD",styannelidsIds ) ) );

        //中国生物多样性红色名录濒危等级
        list.add( new Replace( "styannelidsChinaEndangeredCategory1",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","CR",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsChinaEndangeredCategory2",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","EN",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsChinaEndangeredCategory3",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","VU",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsChinaEndangeredCategory4",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","NT",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsChinaEndangeredCategory5",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","LC",styannelidsIds ) ) );
        list.add( new Replace( "styannelidsChinaEndangeredCategory6",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","DD",styannelidsIds ) ) );

        //特有种情况
        List<Object> styannelidsEndemicSpecies1 = organismRepository.getOrganismByEndemismAndIds("中国特有",styannelidsIds);
        List<Object> styannelidsEndemicSpecies2 = organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",styannelidsIds);
        List<Object> styannelidsEndemicSpecies3 = organismRepository.getOrganismByEndemismAndIds("贵州地方特有",styannelidsIds);
        list.add( new Replace( "styannelidsEndemicSpeciesNum1",""+styannelidsEndemicSpecies1.size() ) );
        list.add( new Replace( "styannelidsEndemicSpeciesNum2",""+styannelidsEndemicSpecies2.size() ) );
        list.add( new Replace( "styannelidsEndemicSpeciesNum3",""+styannelidsEndemicSpecies3.size() ) );
        list.add( new Replace( "styannelidsEndemicSpecies1",getSpecies( styannelidsEndemicSpecies1 ) ) );
        list.add( new Replace( "styannelidsEndemicSpecies2",getSpecies( styannelidsEndemicSpecies2 ) ) );
        list.add( new Replace( "styannelidsEndemicSpecies3",getSpecies( styannelidsEndemicSpecies3 ) ) );

        //外来物种情况
        List<Object> styannelidsAlienSpecies = organismRepository.getOrganismByEndemismAndIds("|外来",styannelidsIds);
        list.add( new Replace( "styannelidsAlienSpeciesNum", ""+styannelidsAlienSpecies.size()) );
        list.add( new Replace( "styannelidsAlienSpecies",getSpecies( styannelidsAlienSpecies ) ) );


        //多足动物亚门
        Object[] stymultipedNum = (Object[]) diversityReportRepository.getCountBySubPhylumnAndArea("多足动物亚门",provinceIds);
        list.add( new Replace( "stymultipedNum1",""+stymultipedNum[0] ) );
        list.add( new Replace( "stymultipedNum2",""+stymultipedNum[1] ) );
        list.add( new Replace( "stymultipedNum3",""+stymultipedNum[2] ) );
        list.add( new Replace( "stymultipedNum4",""+stymultipedNum[3] ) );
        list.add( new Replace( "stymultipedNum5",""+stymultipedNum[4] ) );

        Object[] styareaMultipedNum = (Object[]) diversityReportRepository.getCountBySubPhylumnAndArea( "多足动物亚门",areaIds );
        list.add( new Replace( "styareaMultipedNum1",""+styareaMultipedNum[0] ) );
        list.add( new Replace( "styareaMultipedNum2",""+styareaMultipedNum[1] ) );
        list.add( new Replace( "styareaMultipedNum3",""+styareaMultipedNum[2] ) );
        list.add( new Replace( "styareaMultipedNum4",""+styareaMultipedNum[3] ) );
        list.add( new Replace( "styareaMultipedNum5",""+styareaMultipedNum[4] ) );

        //地区多足动物亚门百分比计算
        list.add( new Replace( "styareaMultipedPCT1",getPCT2( styareaMultipedNum[4],5488 ) ) );
        list.add( new Replace( "styareaMultipedPCT2",getPCT2( styareaMultipedNum[4],673 )  ) );
        list.add( new Replace( "styareaMultipedPCT3",getPCT2( styareaMultipedNum[4], stymultipedNum[4] )  ) );

        //通过门筛选下来的物种id集合
        List<Long> stymultipedIds = taxonomyRepository.getIdBySubPhylumn("多足动物亚门",areaIds);
        stymultipedIds = stymultipedIds.size()>0?stymultipedIds:null;

        //IUCN 物种红色名录濒危等级
        list.add( new Replace( "stymultipedEndangeredCategory1",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","EN",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedEndangeredCategory2",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","VU",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedEndangeredCategory3",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","NT",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedEndangeredCategory4",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","LC",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedEndangeredCategory5",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","DD",stymultipedIds ) ) );

        //中国生物多样性红色名录濒危等级
        list.add( new Replace( "stymultipedChinaEndangeredCategory1",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","CR",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedChinaEndangeredCategory2",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","EN",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedChinaEndangeredCategory3",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","VU",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedChinaEndangeredCategory4",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","NT",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedChinaEndangeredCategory5",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","LC",stymultipedIds ) ) );
        list.add( new Replace( "stymultipedChinaEndangeredCategory6",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","DD",stymultipedIds ) ) );

        //特有种情况
        List<Object> stymultipedEndemicSpecies1 = organismRepository.getOrganismByEndemismAndIds("中国特有",stymultipedIds);
        List<Object> stymultipedEndemicSpecies2 = organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",stymultipedIds);
        List<Object> stymultipedEndemicSpecies3 = organismRepository.getOrganismByEndemismAndIds("贵州地方特有",stymultipedIds);
        list.add( new Replace( "stymultipedEndemicSpeciesNum1",""+stymultipedEndemicSpecies1.size() ) );
        list.add( new Replace( "stymultipedEndemicSpeciesNum2",""+stymultipedEndemicSpecies2.size() ) );
        list.add( new Replace( "stymultipedEndemicSpeciesNum3",""+stymultipedEndemicSpecies3.size() ) );
        list.add( new Replace( "stymultipedEndemicSpecies1",getSpecies( stymultipedEndemicSpecies1 ) ) );
        list.add( new Replace( "stymultipedEndemicSpecies2",getSpecies( stymultipedEndemicSpecies2 ) ) );
        list.add( new Replace( "stymultipedEndemicSpecies3",getSpecies( stymultipedEndemicSpecies3 ) ) );

        //外来物种情况
        List<Object> stymultipedAlienSpecies = organismRepository.getOrganismByEndemismAndIds("|外来",stymultipedIds);
        list.add( new Replace( "stymultipedAlienSpeciesNum", ""+stymultipedAlienSpecies.size()) );
        list.add( new Replace( "stymultipedAlienSpecies",getSpecies( stymultipedAlienSpecies ) ) );


        //蛛形纲
        Object[] styspiderNum = (Object[]) diversityReportRepository.getCountByClassAndArea("蛛形纲",provinceIds);
        list.add( new Replace( "styspiderNum1",""+styspiderNum[0] ) );
        list.add( new Replace( "styspiderNum2",""+styspiderNum[1] ) );
        list.add( new Replace( "styspiderNum3",""+styspiderNum[2] ) );
        list.add( new Replace( "styspiderNum4",""+styspiderNum[3] ) );

        Object[] styareaSpiderNum = (Object[]) diversityReportRepository.getCountByClassAndArea( "蛛形纲",areaIds );
        list.add( new Replace( "styareaSpiderNum1",""+styareaSpiderNum[0] ) );
        list.add( new Replace( "styareaSpiderNum2",""+styareaSpiderNum[1] ) );
        list.add( new Replace( "styareaSpiderNum3",""+styareaSpiderNum[2] ) );
        list.add( new Replace( "styareaSpiderNum4",""+styareaSpiderNum[3] ) );

        //地区蛛形纲百分比计算
        list.add( new Replace( "styareaSpiderPCT1",getPCT2( styareaSpiderNum[3],5488 ) ) );
        list.add( new Replace( "styareaSpiderPCT2",getPCT2( styareaSpiderNum[3],673 )  ) );
        list.add( new Replace( "styareaSpiderPCT3",getPCT2( styareaSpiderNum[3], styspiderNum[3] )  ) );

        //通过门筛选下来的物种id集合
        List<Long> styspiderIds = taxonomyRepository.getIdByTClass("蛛形纲",areaIds);
        styspiderIds = styspiderIds.size()>0?styspiderIds:null;

        //IUCN 物种红色名录濒危等级
        list.add( new Replace( "styspiderEndangeredCategory1",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","EN",styspiderIds ) ) );
        list.add( new Replace( "styspiderEndangeredCategory2",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","VU",styspiderIds ) ) );
        list.add( new Replace( "styspiderEndangeredCategory3",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","NT",styspiderIds ) ) );
        list.add( new Replace( "styspiderEndangeredCategory4",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","LC",styspiderIds ) ) );
        list.add( new Replace( "styspiderEndangeredCategory5",""+conservationStatusRepository.getCount( "IUCN物种红色名录等级","DD",styspiderIds ) ) );

        //中国生物多样性红色名录濒危等级
        list.add( new Replace( "styspiderChinaEndangeredCategory1",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","CR",styspiderIds ) ) );
        list.add( new Replace( "styspiderChinaEndangeredCategory2",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","EN",styspiderIds ) ) );
        list.add( new Replace( "styspiderChinaEndangeredCategory3",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","VU",styspiderIds ) ) );
        list.add( new Replace( "styspiderChinaEndangeredCategory4",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","NT",styspiderIds ) ) );
        list.add( new Replace( "styspiderChinaEndangeredCategory5",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","LC",styspiderIds ) ) );
        list.add( new Replace( "styspiderChinaEndangeredCategory6",""+conservationStatusRepository.getCount( "中国生物多样性红色名录等级","DD",styspiderIds ) ) );

        //特有种情况
        List<Object> styspiderEndemicSpecies1 = organismRepository.getOrganismByEndemismAndIds("中国特有",styspiderIds);
        List<Object> styspiderEndemicSpecies2 = organismRepository.getOrganismByEndemismAndIds("贵州狭域分布",styspiderIds);
        List<Object> styspiderEndemicSpecies3 = organismRepository.getOrganismByEndemismAndIds("贵州地方特有",styspiderIds);
        list.add( new Replace( "styspiderEndemicSpeciesNum1",""+styspiderEndemicSpecies1.size() ) );
        list.add( new Replace( "styspiderEndemicSpeciesNum2",""+styspiderEndemicSpecies2.size() ) );
        list.add( new Replace( "styspiderEndemicSpeciesNum3",""+styspiderEndemicSpecies3.size() ) );
        list.add( new Replace( "styspiderEndemicSpecies1",getSpecies( styspiderEndemicSpecies1 ) ) );
        list.add( new Replace( "styspiderEndemicSpecies2",getSpecies( styspiderEndemicSpecies2 ) ) );
        list.add( new Replace( "styspiderEndemicSpecies3",getSpecies( styspiderEndemicSpecies3 ) ) );

        //外来物种情况
        List<Object> styspiderAlienSpecies = organismRepository.getOrganismByEndemismAndIds("|外来",styspiderIds);
        list.add( new Replace( "styspiderAlienSpeciesNum", ""+styspiderAlienSpecies.size()) );
        list.add( new Replace( "styspiderAlienSpecies",getSpecies( styspiderAlienSpecies ) ) );

        for(Replace replaceAll:list){
            content = content.replaceAll( replaceAll.getWordName(),replaceAll.getNewData() );
        }

        return content;
    }
    
    /**
     * 410-620
     * @param txt
     * @param provinceIds
     * @param areaIds
     * @return
     */
    public String getContent3(String txt, List<Long> provinceIds, List<Long> areaIds){
        provinceIds = provinceIds.size()>0?provinceIds:null;
        areaIds = areaIds.size()>0?areaIds:null;
        try {
            if (areaIds != null){
                Object[] object =(Object[]) diversityReportRepository.getCountByArea(areaIds);
                txt = txt.replaceAll("stybotanyNum1",object[0]+"").replaceAll("stybotanyNum2",object[1]+"").replaceAll("stybotanyNum3",object[2]+"")
                    .replaceAll("stybotanyNum4",object[3]+"").replaceAll("stybotanyNum5",object[4]+"").replaceAll("stybotanyNum6",object[5]+"");
                
                Object[] o = (Object[])diversityReportRepository.getCountBySubPhylumnAndArea("被子植物亚门",areaIds);
                txt = txt.replaceAll("styareaAngiospermaeNum1",o[0]+"").replaceAll("styareaAngiospermaeNum2",o[1]+"").replaceAll("styareaAngiospermaeNum3",o[2]+"")
                    .replaceAll("styareaAngiospermaeNum4",o[3]+"").replaceAll("styareaAngiospermaeNum5",o[4]+"");
                
                //占世界比例
                txt = txt.replaceAll("styareaAngiospermaePCT1",getPCT2(Integer.parseInt(o[4]+""),5488));
                //占中国比例
                txt = txt.replaceAll("styareaAngiospermaePCT2",getPCT2(Integer.parseInt(o[4]+""),673));
                //占贵州省比例
                if (provinceIds != null){
                    Object[] obj =(Object[]) diversityReportRepository.getCountByArea(provinceIds);
                    txt = txt.replaceAll("styareaAngiospermaePCT3",getPCT2(Integer.parseInt(o[4]+""),Integer.parseInt(obj[4]+"")));
                }
                
                
                
            }
            if (provinceIds != null){
                Object[] object =(Object[]) diversityReportRepository.getCountByArea(provinceIds);
                txt = txt.replaceAll("stybotanyNum1",object[0]+"").replaceAll("stybotanyNum2",object[1]+"").replaceAll("stybotanyNum3",object[2]+"")
                    .replaceAll("stybotanyNum4",object[3]+"").replaceAll("stybotanyNum5",object[4]+"").replaceAll("stybotanyNum6",object[5]+"");
    
                //贵州省
                Object[] o = (Object[])diversityReportRepository.getCountBySubPhylumnAndArea("被子植物亚门",provinceIds);
                txt = txt.replaceAll("styangiospermaeNum1",o[0]+"").replaceAll("styangiospermaeNum2",o[1]+"").replaceAll("styangiospermaeNum3",o[2]+"")
                    .replaceAll("styangiospermaeNum4",o[3]+"").replaceAll("styangiospermaeNum5",o[4]+"");
            
            }
            if (areaIds == null && provinceIds == null){
                txt = txt.replaceAll("stybotanyNum1","0").replaceAll("stybotanyNum2","0").replaceAll("stybotanyNum3","0")
                    .replaceAll("stybotanyNum4","0").replaceAll("stybotanyNum5","0").replaceAll("stybotanyNum6","0");
            }
            
            //国家重点保护野生植物种类
            List<Long> bIds = taxonomyRepository.getIdByPhylumn("被子植物亚门",areaIds);
            bIds= bIds.size()>0?bIds:null;
            txt = txt.replaceAll("styangiospermaeSpeciesNum1",conservationStatusRepository.getCount("国家重点保护野生植物种类","I级",bIds)+"");
            List<Long> ids = conservationStatusRepository.getIds("国家重点保护野生植物种类","I级",bIds);
            List<Organism> organisms = new ArrayList<Organism>();
            for (int i = 0;i < ids.size();i++) {
                organisms.add(organismService.findOne(ids.get(i)));
            }
            StringBuffer stringBuffer = new StringBuffer();
            for (int j = 0;j < organisms.size();j++){
                stringBuffer.append(organisms.get(j).getName()+" "+organisms.get(j).getLatinName()+"("+organisms.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("styangiospermaeSpecies1",stringBuffer+"");
    
            txt = txt.replaceAll("styangiospermaeSpeciesNum2",conservationStatusRepository.getCount("国家重点保护野生植物种类","II级",bIds)+"");
            List<Long> ids1 = conservationStatusRepository.getIds("国家重点保护野生植物种类","II级",bIds);
            List<Organism> organisms1 = new ArrayList<Organism>();
            for (int i = 0;i < ids1.size();i++) {
                organisms.add(organismService.findOne(ids1.get(i)));
            }
            StringBuffer stringBuffer1 = new StringBuffer();
            for (int j = 0;j < organisms1.size();j++){
                stringBuffer1.append(organisms.get(j).getName()+" "+organisms.get(j).getLatinName()+"("+organisms.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("styangiospermaeSpecies2",stringBuffer1+"");
            
            // IUCN物种红色名录濒危等级
            txt = txt.replaceAll("styangiospermaeEndangeredCategory1",conservationStatusRepository.getCount("IUCN物种红色名录等级","濒危（EN）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeEndangeredCategory2",conservationStatusRepository.getCount("IUCN物种红色名录等级","易危（VU）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeEndangeredCategory3",conservationStatusRepository.getCount("IUCN物种红色名录等级","近危（NT）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeEndangeredCategory4",conservationStatusRepository.getCount("IUCN物种红色名录等级","低危（LC）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeEndangeredCategory5",conservationStatusRepository.getCount("IUCN物种红色名录等级","数据缺乏（DD）",bIds)+"");
            
            //中国生物多样性红色名录（高等植物）濒危等级
            txt = txt.replaceAll("styangiospermaeChinaEndangeredCategory1",conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危（CR）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeChinaEndangeredCategory2",conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危（EN）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeChinaEndangeredCategory3",conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危（VU）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeChinaEndangeredCategory4",conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危（NT）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeChinaEndangeredCategory5",conservationStatusRepository.getCount("中国生物多样性红色名录等级","低危（LC）",bIds)+"");
            txt = txt.replaceAll("styangiospermaeChinaEndangeredCategory6",conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏（DD）",bIds)+"");
            
            //濒危野生动植物种国际贸易公约（CITES）种类
            txt = txt.replaceAll("styangiospermaeEndangeredCITES1",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录I",bIds)+"");
            txt = txt.replaceAll("styangiospermaeEndangeredCITES2",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录II",bIds)+"");
            txt = txt.replaceAll("styangiospermaeEndangeredCITES3",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录III",bIds)+"");
            
            //特有种情况
            List<Object> ooobs1 = organismService.getOrganismByEndemismAndIds("中国特有",bIds);
            txt = txt.replaceAll("styangiospermaeEndemicSpeciesNum1",ooobs1.size()+"");
            txt = txt.replaceAll("styangiospermaeEndemicSpecies1",getSpecies(ooobs1));
    
            List<Object> ooobs2 = organismService.getOrganismByEndemismAndIds("贵州狭域分布",bIds);
            txt = txt.replaceAll("styangiospermaeEndemicSpeciesNum2",ooobs2.size()+"");
            txt = txt.replaceAll("styangiospermaeEndemicSpecies2",getSpecies(ooobs2));
    
            List<Object> ooobs3 = organismService.getOrganismByEndemismAndIds("贵州地方特有",bIds);
            txt = txt.replaceAll("styangiospermaeEndemicSpeciesNum3",ooobs3.size()+"");
            txt = txt.replaceAll("styangiospermaeEndemicSpecies3",getSpecies(ooobs3));
    
            List<Object> ooobs4 = organismService.getOrganismByEndemismAndIds("外来",bIds);
            txt = txt.replaceAll("styangiospermaeAlienSpeciesNum",ooobs4.size()+"");
            txt = txt.replaceAll("styangiospermaeAlienSpecies",getSpecies(ooobs4));
            
//            Integer num = null;
//            List<Organism> organisms2=organismService.findAllByEndemism("中国特有",bIds);
//            num = organisms2.size();
//            txt = txt.replaceAll("styangiospermaeEndemicSpeciesNum1",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styangiospermaeEndemicSpecies1",organisms2.get(i).getName()+" "+organisms2.get(i).getLatinName()+"("+organisms2.get(i).getNamedInfo()+")"+"\n");
//            }
//            List<Organism> objects = organismService.findAllByEndemism("贵州狭域分布",bIds);
//            num = objects.size();
//            txt = txt.replaceAll("styangiospermaeEndemicSpeciesNum2",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styangiospermaeEndemicSpecies2",objects.get(i).getName()+" "+objects.get(i).getLatinName()+"("+objects.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            List<Organism> objects1 = organismService.findAllByEndemism("贵州地方特有",bIds);
//            num = objects1.size();
//            txt = txt.replaceAll("styangiospermaeEndemicSpeciesNum3",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styangiospermaeEndemicSpecies3",objects1.get(i).getName()+" "+objects1.get(i).getLatinName()+"("+objects1.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            //外来物种情况
//            List<Organism> organisms3=organismService.findAllByEndemism("外来",bIds);
//            num = organisms3.size();
//            txt = txt.replaceAll("styangiospermaeAlienSpeciesNum",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styangiospermaeAlienSpecies",organisms3.get(i).getName()+" "+organisms3.get(i).getLatinName()+"("+organisms3.get(i).getNamedInfo()+")"+"\n");
//            }
            
            //************裸子植物亚门**********************
            List<Long> lIds = taxonomyRepository.getIdByPhylumn("裸子植物亚门",areaIds);
            lIds= lIds.size()>0?lIds:null;
            Object[] oo = (Object[]) diversityReportRepository.getCountBySubPhylumnAndArea("裸子植物亚门",provinceIds);
            for (int i = 0;i < oo.length;i++) {
                txt = txt.replaceAll("stygymnospermaeNum1",oo[2]+"").replaceAll("stygymnospermaeNum2",oo[3]+"").replaceAll("stygymnospermaeNum3",oo[4]+"");
            }
            Object[] oo1 = (Object[]) diversityReportRepository.getCountBySubPhylumnAndArea("裸子植物亚门",areaIds);
            for (int i = 0;i < oo1.length;i++) {
                txt = txt.replaceAll("styareaGymnospermaeNum1",oo1[2]+"").replaceAll("styareaGymnospermaeNum2",oo1[3]+"").replaceAll("styareaGymnospermaeNum3",oo1[4]+"");
            }
            
            //比例
            txt = txt.replaceAll("styareaGymnospermaePCT1",getPCT2(oo1[4],5488));
            txt = txt.replaceAll("styareaGymnospermaePCT2",getPCT2(oo1[4],673));
            txt = txt.replaceAll("styareaGymnospermaePCT3",getPCT2(oo1[4],oo[4]));
            
            //国家重点保护野生植物种类
            txt = txt.replaceAll("stygymnospermaeSpeciesNum1",conservationStatusRepository.getCount("国家重点保护野生植物种类","I级",lIds)+"");
            List<Long> aids = conservationStatusRepository.getIds("国家重点保护野生植物种类","I级",lIds);
            List<Organism> organismsa = new ArrayList<Organism>();
            for (int i = 0;i < aids.size();i++) {
                organisms.add(organismService.findOne(aids.get(i)));
            }
            StringBuffer stringBuffera = new StringBuffer();
            for (int j = 0;j < organismsa.size();j++){
                stringBuffera.append(organismsa.get(j).getName()+" "+organismsa.get(j).getLatinName()+"("+organismsa.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("stygymnospermaeSpecies1",stringBuffera+"");
    
            txt = txt.replaceAll("stygymnospermaeSpeciesNum2",conservationStatusRepository.getCount("国家重点保护野生植物种类","II级",lIds)+"");
            List<Long> aids1 = conservationStatusRepository.getIds("国家重点保护野生植物种类","II级",lIds);
            List<Organism> organismsa1 = new ArrayList<Organism>();
            for (int i = 0;i < aids1.size();i++) {
                organismsa1.add(organismService.findOne(aids1.get(i)));
            }
            StringBuffer stringBuffera1 = new StringBuffer();
            for (int j = 0;j < organismsa1.size();j++){
                stringBuffera1.append(organismsa1.get(j).getName()+" "+organismsa1.get(j).getLatinName()+"("+organismsa1.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("stygymnospermaeSpecies2",stringBuffera1+"");
    
            // IUCN物种红色名录濒危等级
            txt = txt.replaceAll("stygymnospermaeEndangeredCategory1",conservationStatusRepository.getCount("IUCN物种红色名录等级","濒危（EN）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeEndangeredCategory2",conservationStatusRepository.getCount("IUCN物种红色名录等级","易危（VU）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeEndangeredCategory3",conservationStatusRepository.getCount("IUCN物种红色名录等级","近危（NT）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeEndangeredCategory4",conservationStatusRepository.getCount("IUCN物种红色名录等级","低危（LC）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeEndangeredCategory5",conservationStatusRepository.getCount("IUCN物种红色名录等级","数据缺乏（DD）",lIds)+"");
    
            //中国生物多样性红色名录（高等植物）濒危等级
            txt = txt.replaceAll("stygymnospermaeChinaEndangeredCategory1",conservationStatusRepository.getCount("中国生物多样性红色名录等级","极危（CR）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeChinaEndangeredCategory2",conservationStatusRepository.getCount("中国生物多样性红色名录等级","濒危（EN）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeChinaEndangeredCategory3",conservationStatusRepository.getCount("中国生物多样性红色名录等级","易危（VU）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeChinaEndangeredCategory4",conservationStatusRepository.getCount("中国生物多样性红色名录等级","近危（NT）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeChinaEndangeredCategory5",conservationStatusRepository.getCount("中国生物多样性红色名录等级","低危（LC）",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeChinaEndangeredCategory6",conservationStatusRepository.getCount("中国生物多样性红色名录等级","数据缺乏（DD）",lIds)+"");
    
            //濒危野生动植物种国际贸易公约（CITES）种类
            txt = txt.replaceAll("stygymnospermaeEndangeredCITES1",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录I",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeEndangeredCITES2",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录II",lIds)+"");
            txt = txt.replaceAll("stygymnospermaeEndangeredCITES3",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录III",lIds)+"");
    
            //特有种情况
            List<Object> oobs1 = organismService.getOrganismByEndemismAndIds("中国特有",lIds);
            txt = txt.replaceAll("stygymnospermaeEndemicSpeciesNum1",oobs1.size()+"");
            txt = txt.replaceAll("stygymnospermaeEndemicSpecies1",getSpecies(oobs1));
    
            List<Object> oobs2 = organismService.getOrganismByEndemismAndIds("贵州狭域分布",lIds);
            txt = txt.replaceAll("stygymnospermaeEndemicSpeciesNum2",oobs2.size()+"");
            txt = txt.replaceAll("stygymnospermaeEndemicSpecies2",getSpecies(oobs2));
    
            List<Object> oobs3 = organismService.getOrganismByEndemismAndIds("贵州地方特有",lIds);
            txt = txt.replaceAll("stygymnospermaeEndemicSpeciesNum3",oobs3.size()+"");
            txt = txt.replaceAll("stygymnospermaeEndemicSpecies3",getSpecies(oobs3));
    
            List<Object> oobs4 = organismService.getOrganismByEndemismAndIds("外来",lIds);
            txt = txt.replaceAll("stygymnospermaeAlienSpeciesNum",oobs4.size()+"");
            txt = txt.replaceAll("stygymnospermaeAlienSpecies",getSpecies(oobs4));
            
//            List<Organism> organismsa2=organismService.findAllByEndemism("中国特有",lIds);
//            num = organismsa2.size();
//            txt = txt.replaceAll("stygymnospermaeEndemicSpeciesNum1",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stygymnospermaeEndemicSpecies1",organismsa2.get(i).getName()+" "+organismsa2.get(i).getLatinName()+"("+organismsa2.get(i).getNamedInfo()+")"+"\n");
//            }
//            List<Organism> objectsa = organismService.findAllByEndemism("贵州狭域分布",lIds);
//            num = objectsa.size();
//            txt = txt.replaceAll("stygymnospermaeEndemicSpeciesNum2",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stygymnospermaeEndemicSpecies2",objectsa.get(i).getName()+" "+objectsa.get(i).getLatinName()+"("+objectsa.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            List<Organism> objectsa1 = organismService.findAllByEndemism("贵州地方特有",lIds);
//            num = objectsa1.size();
//            txt = txt.replaceAll("stygymnospermaeEndemicSpeciesNum3",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stygymnospermaeEndemicSpecies3",objectsa1.get(i).getName()+" "+objectsa1.get(i).getLatinName()+"("+objectsa1.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            //外来物种情况
//            List<Organism> organismsa3=organismService.findAllByEndemism("外来",lIds);
//            num = organismsa3.size();
//            txt = txt.replaceAll("stygymnospermaeAlienSpeciesNum",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stygymnospermaeAlienSpecies",organismsa3.get(i).getName()+" "+organismsa3.get(i).getLatinName()+"("+organismsa3.get(i).getNamedInfo()+")"+"\n");
//            }
            
            
            //*************************   蕨类植物门    ****************************
            List<Long> jIds = taxonomyRepository.getIdByPhylumn("蕨类",areaIds);
            jIds= jIds.size()>0?jIds:null;
            Object[] oo2 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("蕨类",provinceIds);
            for (int i = 0;i < oo2.length;i++) {
                txt = txt.replaceAll("styfernsNum1",oo2[0]+"").replaceAll("styfernsNum2",oo2[1]+"").replaceAll("styfernsNum3",oo2[2]+"")
                .replaceAll("styfernsNum4",oo2[3]+"").replaceAll("styfernsNum5",oo2[4]+"");
            }
            Object[] oo3 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("蕨类",areaIds);
            for (int i = 0;i < oo3.length;i++) {
                txt = txt.replaceAll("styareaFernsNum1",oo3[0]+"").replaceAll("styareaFernsNum2",oo3[1]+"").replaceAll("styareaFernsNum3",oo3[2]+"")
                .replaceAll("styareaFernsNum4",oo3[3]+"").replaceAll("styareaFernsNum5",oo3[4]+"");
            }
    
            //比例
            txt = txt.replaceAll("styareaFernsPCT1",getPCT2(oo3[4],5488));
            txt = txt.replaceAll("styareaFernsPCT2",getPCT2(oo3[4],673));
            txt = txt.replaceAll("styareaFernsPCT3",getPCT2(oo3[4],oo2[4]));
    
            //国家重点保护野生植物种类
            txt = txt.replaceAll("styfernsSpeciesNum1",conservationStatusRepository.getCount("国家重点保护野生植物种类","I级",jIds)+"");
            List<Long> aids2 = conservationStatusRepository.getIds("国家重点保护野生植物种类","I级",jIds);
            List<Organism> organism1 = new ArrayList<Organism>();
            for (int i = 0;i < aids2.size();i++) {
                organism1.add(organismService.findOne(aids2.get(i)));
            }
            StringBuffer stringBuffer2 = new StringBuffer();
            for (int j = 0;j < organism1.size();j++){
                stringBuffer2.append(organism1.get(j).getName()+" "+organism1.get(j).getLatinName()+"("+organism1.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("styfernsSpecies1",stringBuffer2+"");
    
            txt = txt.replaceAll("styfernsSpeciesNum2",conservationStatusRepository.getCount("国家重点保护野生植物种类","II级",jIds)+"");
            List<Long> aids3 = conservationStatusRepository.getIds("国家重点保护野生植物种类","II级",jIds);
            List<Organism> organism2 = new ArrayList<Organism>();
            for (int i = 0;i < aids3.size();i++) {
                organism2.add(organismService.findOne(aids3.get(i)));
            }
            StringBuffer stringBuffer3 = new StringBuffer();
            for (int j = 0;j < organism2.size();j++){
                stringBuffer3.append(organism2.get(j).getName()+" "+organism2.get(j).getLatinName()+"("+organism2.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("styfernsSpecies2",stringBuffer3+"");
    
            // IUCN物种红色名录濒危等级
            txt = txt.replaceAll("styfernsEndangeredCategory1",conservationStatusRepository.getCount("IUCN物种红色名录等级","濒危（EN）",jIds)+"");
            txt = txt.replaceAll("styfernsEndangeredCategory2",conservationStatusRepository.getCount("IUCN物种红色名录等级","易危（VU）",jIds)+"");
            txt = txt.replaceAll("styfernsEndangeredCategory3",conservationStatusRepository.getCount("IUCN物种红色名录等级","近危（NT）",jIds)+"");
            txt = txt.replaceAll("styfernsEndangeredCategory4",conservationStatusRepository.getCount("IUCN物种红色名录等级","低危（LC）",jIds)+"");
            txt = txt.replaceAll("styfernsEndangeredCategory5",conservationStatusRepository.getCount("IUCN物种红色名录等级","数据缺乏（DD）",jIds)+"");

            //濒危野生动植物种国际贸易公约（CITES）种类
            txt = txt.replaceAll("styfernsEndangeredCITES1",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录I",jIds)+"");
            txt = txt.replaceAll("styfernsEndangeredCITES2",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录II",jIds)+"");
            txt = txt.replaceAll("styfernsEndangeredCITES3",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录III",jIds)+"");
    
            //特有种情况
            List<Object> oobs9 = organismService.getOrganismByEndemismAndIds("中国特有",jIds);
            txt = txt.replaceAll("styfernsEndemicSpeciesNum1",oobs9.size()+"");
            txt = txt.replaceAll("styfernsEndemicSpecies1",getSpecies(oobs9));
    
            List<Object> oobs5 = organismService.getOrganismByEndemismAndIds("贵州狭域分布",jIds);
            txt = txt.replaceAll("styfernsEndemicSpeciesNum2",oobs5.size()+"");
            txt = txt.replaceAll("styfernsEndemicSpecies2",getSpecies(oobs5));
    
            List<Object> oobs6 = organismService.getOrganismByEndemismAndIds("贵州地方特有",jIds);
            txt = txt.replaceAll("styfernsEndemicSpeciesNum3",oobs6.size()+"");
            txt = txt.replaceAll("styfernsEndemicSpecies3",getSpecies(oobs6));
    
            List<Object> oobs7 = organismService.getOrganismByEndemismAndIds("外来",jIds);
            txt = txt.replaceAll("styfernsAlienSpeciesNum",oobs7.size()+"");
            txt = txt.replaceAll("styfernsAlienSpecies",getSpecies(oobs7));
    
//            List<Organism> organism3=organismService.findAllByEndemism("中国特有",jIds);
//            num = organism3.size();
//            txt = txt.replaceAll("styfernsEndemicSpeciesNum1",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styfernsEndemicSpecies1",organism3.get(i).getName()+" "+organism3.get(i).getLatinName()+"("+organism3.get(i).getNamedInfo()+")"+"\n");
//            }
//            List<Organism> object1 = organismService.findAllByEndemism("贵州狭域分布",jIds);
//            num = object1.size();
//            txt = txt.replaceAll("styfernsEndemicSpeciesNum2",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styfernsEndemicSpecies2",object1.get(i).getName()+" "+object1.get(i).getLatinName()+"("+object1.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            List<Organism> object2 = organismService.findAllByEndemism("贵州地方特有",jIds);
//            num = object2.size();
//            txt = txt.replaceAll("styfernsEndemicSpeciesNum3",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styfernsEndemicSpecies3",object2.get(i).getName()+" "+object2.get(i).getLatinName()+"("+object2.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            //外来物种情况
//            List<Organism> organism4=organismService.findAllByEndemism("外来",jIds);
//            num = organism4.size();
//            txt = txt.replaceAll("styfernsAlienSpeciesNum",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styfernsAlienSpecies",organism4.get(i).getName()+" "+organism4.get(i).getLatinName()+"("+organism4.get(i).getNamedInfo()+")"+"\n");
//            }
            
            
            //***********************   苔藓植物门   ***********************************
            List<Long> tIds = taxonomyRepository.getIdByPhylumn("苔藓植物门",areaIds);
            tIds= tIds.size()>0?tIds:null;
            Object[] oo4 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("苔藓植物门",provinceIds);
            for (int i = 0;i < oo4.length;i++) {
                txt = txt.replaceAll("stybryophyteNum1",oo4[0]+"").replaceAll("stybryophyteNum2",oo4[1]+"").replaceAll("stybryophyteNum3",oo4[2]+"")
                    .replaceAll("stybryophyteNum4",oo4[3]+"").replaceAll("stybryophyteNum5",oo4[4]+"");
            }
            Object[] oo5 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("苔藓植物门",areaIds);
            for (int i = 0;i < oo5.length;i++) {
                txt = txt.replaceAll("styareaBryophyteNum1",oo5[0]+"").replaceAll("styareaBryophyteNum2",oo5[1]+"").replaceAll("styareaBryophyteNum3",oo5[2]+"")
                    .replaceAll("styareaBryophyteNum4",oo5[3]+"").replaceAll("styareaBryophyteNum5",oo5[4]+"");
            }
    
            //比例
            txt = txt.replaceAll("styareaBryophytePCT1",getPCT2(oo5[4],5488));
            txt = txt.replaceAll("styareaBryophytePCT2",getPCT2(oo5[4],673));
            txt = txt.replaceAll("styareaBryophytePCT3",getPCT2(oo5[4],oo4[4]));
    
            //国家重点保护野生植物种类
            txt = txt.replaceAll("stybryophyteSpeciesNum1",conservationStatusRepository.getCount("国家重点保护野生植物种类","I级",tIds)+"");
            List<Long> id1 = conservationStatusRepository.getIds("国家重点保护野生植物种类","I级",tIds);
            List<Organism> organism5 = new ArrayList<Organism>();
            for (int i = 0;i < id1.size();i++) {
                organism5.add(organismService.findOne(id1.get(i)));
            }
            StringBuffer stringBuffer4 = new StringBuffer();
            for (int j = 0;j < organism5.size();j++){
                stringBuffer4.append(organism5.get(j).getName()+" "+organism5.get(j).getLatinName()+"("+organism5.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("stybryophyteSpecies1",stringBuffer4+"");
    
            txt = txt.replaceAll("stybryophyteSpeciesNum2",conservationStatusRepository.getCount("国家重点保护野生植物种类","II级",tIds)+"");
            List<Long> id2 = conservationStatusRepository.getIds("国家重点保护野生植物种类","II级",tIds);
            List<Organism> organism6 = new ArrayList<Organism>();
            for (int i = 0;i < id2.size();i++) {
                organism6.add(organismService.findOne(id2.get(i)));
            }
            StringBuffer stringBuffer5 = new StringBuffer();
            for (int j = 0;j < organism6.size();j++){
                stringBuffer5.append(organism6.get(j).getName()+" "+organism6.get(j).getLatinName()+"("+organism6.get(j).getNamedInfo()+")"+"\n");
            }
            txt = txt.replaceAll("stybryophyteSpecies2",stringBuffer5+"");
    
            // IUCN物种红色名录濒危等级
            txt = txt.replaceAll("stybryophyteEndangeredCategory1",conservationStatusRepository.getCount("IUCN物种红色名录等级","濒危（EN）",tIds)+"");
            txt = txt.replaceAll("stybryophyteEndangeredCategory2",conservationStatusRepository.getCount("IUCN物种红色名录等级","易危（VU）",tIds)+"");
            txt = txt.replaceAll("stybryophyteEndangeredCategory3",conservationStatusRepository.getCount("IUCN物种红色名录等级","近危（NT）",tIds)+"");
            txt = txt.replaceAll("stybryophyteEndangeredCategory4",conservationStatusRepository.getCount("IUCN物种红色名录等级","低危（LC）",tIds)+"");
            txt = txt.replaceAll("stybryophyteEndangeredCategory5",conservationStatusRepository.getCount("IUCN物种红色名录等级","数据缺乏（DD）",tIds)+"");
    
            //濒危野生动植物种国际贸易公约（CITES）种类
            txt = txt.replaceAll("stybryophyteEndangeredCITES1",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录I",tIds)+"");
            txt = txt.replaceAll("stybryophyteEndangeredCITES2",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录II",tIds)+"");
            txt = txt.replaceAll("stybryophyteEndangeredCITES3",conservationStatusRepository.getCount("濒危野生动植物种国际贸易公约(CITES) 等级 ","附录III",tIds)+"");
    
            //特有种情况
            List<Object> oob4 = organismService.getOrganismByEndemismAndIds("中国特有",tIds);
            txt = txt.replaceAll("stybryophyteEndemicSpeciesNum1",oob4.size()+"");
            txt = txt.replaceAll("stybryophyteEndemicSpecies1",getSpecies(oob4));
    
            List<Object> oob5 = organismService.getOrganismByEndemismAndIds("贵州狭域分布",tIds);
            txt = txt.replaceAll("stybryophyteEndemicSpeciesNum2",oob5.size()+"");
            txt = txt.replaceAll("stybryophyteEndemicSpecies2",getSpecies(oob5));
    
            List<Object> oob6 = organismService.getOrganismByEndemismAndIds("贵州地方特有",tIds);
            txt = txt.replaceAll("stybryophyteEndemicSpeciesNum3",oob6.size()+"");
            txt = txt.replaceAll("stybryophyteEndemicSpecies3",getSpecies(oob6));
    
            List<Object> oob7 = organismService.getOrganismByEndemismAndIds("外来",tIds);
            txt = txt.replaceAll("stybryophyteAlienSpeciesNum",oob7.size()+"");
            txt = txt.replaceAll("stybryophyteAlienSpecies",getSpecies(oob7));
            
    
//            List<Organism> organism7=organismService.findAllByEndemism("中国特有",tIds);
//            num = organism7.size();
//            txt = txt.replaceAll("stybryophyteEndemicSpeciesNum1",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stybryophyteEndemicSpecies1",organism7.get(i).getName()+" "+organism7.get(i).getLatinName()+"("+organism7.get(i).getNamedInfo()+")"+"\n");
//            }
//            List<Organism> object3 = organismService.findAllByEndemism("贵州狭域分布",tIds);
//            num = object3.size();
//            txt = txt.replaceAll("stybryophyteEndemicSpeciesNum2",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stybryophyteEndemicSpecies2",object3.get(i).getName()+" "+object3.get(i).getLatinName()+"("+object3.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            List<Organism> object4 = organismService.findAllByEndemism("贵州地方特有",tIds);
//            num = object4.size();
//            txt = txt.replaceAll("stybryophyteEndemicSpeciesNum3",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stybryophyteEndemicSpecies3",object4.get(i).getName()+" "+object4.get(i).getLatinName()+"("+object4.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            //外来物种情况
//            List<Organism> organism8=organismService.findAllByEndemism("外来",tIds);
//            num = organism8.size();
//            txt = txt.replaceAll("stybryophyteAlienSpeciesNum",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stybryophyteAlienSpecies",organism8.get(i).getName()+" "+organism8.get(i).getLatinName()+"("+organism8.get(i).getNamedInfo()+")"+"\n");
//            }
            
            
            //*************************** 地衣 *************************************
            List<Long> dIds = taxonomyRepository.getIdByPhylumn("地衣",areaIds);
            dIds= dIds.size()>0?dIds:null;
            Object[] oo6 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("地衣",areaIds);
            for (int i = 0;i < oo6.length;i++) {
                txt = txt.replaceAll("stylichenNum1",oo6[0]+"").replaceAll("stylichenNum2",oo6[1]+"").replaceAll("stylichenNum3",oo6[2]+"")
                    .replaceAll("stylichenNum4",oo6[3]+"").replaceAll("stylichenNum5",oo6[4]+"");
            }
            Object[] oo7 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("地衣",areaIds);
            for (int i = 0;i < oo7.length;i++) {
                txt = txt.replaceAll("styareaLichenNum1",oo7[0]+"").replaceAll("styareaLichenNum2",oo7[1]+"").replaceAll("styareaLichenNum3",oo7[2]+"")
                    .replaceAll("styareaLichenNum4",oo7[3]+"").replaceAll("styareaLichenNum5",oo7[4]+"");
            }
    
            //比例
            txt = txt.replaceAll("styareaLichenPCT1",getPCT2(oo7[4],5488));
            txt = txt.replaceAll("styareaLichenPCT2",getPCT2(oo7[4],673));
            txt = txt.replaceAll("styareaLichenPCT3",getPCT2(oo7[4],oo6[4]));
    
            // IUCN物种红色名录濒危等级
            txt = txt.replaceAll("stylichenEndangeredCategory1",conservationStatusRepository.getCount("IUCN物种红色名录等级","濒危（EN）",dIds)+"");
            txt = txt.replaceAll("stylichenEndangeredCategory2",conservationStatusRepository.getCount("IUCN物种红色名录等级","易危（VU）",dIds)+"");
            txt = txt.replaceAll("stylichenEndangeredCategory3",conservationStatusRepository.getCount("IUCN物种红色名录等级","近危（NT）",dIds)+"");
            txt = txt.replaceAll("stylichenEndangeredCategory4",conservationStatusRepository.getCount("IUCN物种红色名录等级","低危（LC）",dIds)+"");
            txt = txt.replaceAll("stylichenEndangeredCategory5",conservationStatusRepository.getCount("IUCN物种红色名录等级","数据缺乏（DD）",dIds)+"");
    
            //特有种情况
            List<Object> oob = organismService.getOrganismByEndemismAndIds("中国特有",dIds);
            txt = txt.replaceAll("stylichenEndemicSpeciesNum1",oob.size()+"");
            txt = txt.replaceAll("stylichenEndemicSpecies1",getSpecies(oob));
    
            List<Object> oob1 = organismService.getOrganismByEndemismAndIds("贵州狭域分布",dIds);
            txt = txt.replaceAll("stylichenEndemicSpeciesNum2",oob1.size()+"");
            txt = txt.replaceAll("stylichenEndemicSpecies2",getSpecies(oob1));
    
            List<Object> oob2 = organismService.getOrganismByEndemismAndIds("贵州地方特有",dIds);
            txt = txt.replaceAll("stylichenEndemicSpeciesNum3",oob2.size()+"");
            txt = txt.replaceAll("stylichenEndemicSpecies3",getSpecies(oob2));
    
            List<Object> oob3 = organismService.getOrganismByEndemismAndIds("外来",dIds);
            txt = txt.replaceAll("stylichenAlienSpeciesNum",oob3.size()+"");
            txt = txt.replaceAll("stylichenAlienSpecies",getSpecies(oob3));
    
//            List<Organism> organism9=organismService.findAllByEndemism("中国特有",dIds);
//            num = organism9.size();
//            txt = txt.replaceAll("stylichenEndemicSpeciesNum1",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stylichenEndemicSpecies1",organism9.get(i).getName()+" "+organism9.get(i).getLatinName()+"("+organism9.get(i).getNamedInfo()+")"+"\n");
//            }
//            List<Organism> object5 = organismService.findAllByEndemism("贵州狭域分布",dIds);
//            num = object5.size();
//            txt = txt.replaceAll("stylichenEndemicSpeciesNum2",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stylichenEndemicSpecies2",object5.get(i).getName()+" "+object5.get(i).getLatinName()+"("+object5.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            List<Organism> object6 = organismService.findAllByEndemism("贵州地方特有",dIds);
//            num = object6.size();
//            txt = txt.replaceAll("stylichenEndemicSpeciesNum3",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stylichenEndemicSpecies3",object6.get(i).getName()+" "+object6.get(i).getLatinName()+"("+object6.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            //外来物种情况
//            List<Organism> organisms5=organismService.findAllByEndemism("外来",dIds);
//            num = organisms5.size();
//            txt = txt.replaceAll("stylichenAlienSpeciesNum",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("stylichenAlienSpecies",organisms5.get(i).getName()+" "+organisms5.get(i).getLatinName()+"("+organisms5.get(i).getNamedInfo()+")"+"\n");
//            }
            
            
            //*******************************  藻类   ************************************************
            List<Long> zIds = taxonomyRepository.getIdByPhylumn("藻",areaIds);
            zIds= zIds.size()>0?zIds:null;
            Object[] o1 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("藻",provinceIds);
            for (int i = 0;i < o1.length;i++) {
                txt = txt.replaceAll("styalgaeNum1",o1[0]+"").replaceAll("styalgaeNum2",o1[1]+"").replaceAll("styalgaeNum3",o1[2]+"")
                    .replaceAll("styalgaeNum4",o1[3]+"").replaceAll("styalgaeNum5",o1[4]+"");
            }
            Object[] o2 = (Object[]) diversityReportRepository.getCountByPhylumnAndArea("藻",areaIds);
            for (int i = 0;i < o2.length;i++) {
                txt = txt.replaceAll("styareaAlgaeNum1",o2[0]+"").replaceAll("styareaAlgaeNum2",o2[1]+"").replaceAll("styareaAlgaeNum3",o2[2]+"")
                    .replaceAll("styareaAlgaeNum4",o2[3]+"").replaceAll("styareaAlgaeNum5",o2[4]+"");
            }
    
            //比例
            txt = txt.replaceAll("styareaAlgaePCT1",getPCT2(o2[4],5488));
            txt = txt.replaceAll("styareaAlgaePCT2",getPCT2(o2[4],673));
            txt = txt.replaceAll("styareaAlgaePCT3",getPCT2(o2[4],o1[4]));
    
            // IUCN物种红色名录濒危等级
            txt = txt.replaceAll("styalgaeEndangeredCategory1",conservationStatusRepository.getCount("IUCN物种红色名录等级","濒危（EN）",zIds)+"");
            txt = txt.replaceAll("styalgaeEndangeredCategory2",conservationStatusRepository.getCount("IUCN物种红色名录等级","易危（VU）",zIds)+"");
            txt = txt.replaceAll("styalgaeEndangeredCategory3",conservationStatusRepository.getCount("IUCN物种红色名录等级","近危（NT）",zIds)+"");
            txt = txt.replaceAll("styalgaeEndangeredCategory4",conservationStatusRepository.getCount("IUCN物种红色名录等级","低危（LC）",zIds)+"");
            txt = txt.replaceAll("styalgaeEndangeredCategory5",conservationStatusRepository.getCount("IUCN物种红色名录等级","数据缺乏（DD）",zIds)+"");
    
            //特有种情况
            List<Object> objects4 = organismService.getOrganismByEndemismAndIds("中国特有",zIds);
            txt = txt.replaceAll("styalgaeEndemicSpecies1",getSpecies(objects4));
            txt = txt.replaceAll("styalgaeEndemicSpeciesNum1",objects4.size()+"");
            
            List<Object> objects5 = organismService.getOrganismByEndemismAndIds("贵州狭域分布",zIds);
            txt = txt.replaceAll("styalgaeEndemicSpeciesNum2",objects5.size()+"");
            txt = txt.replaceAll("styalgaeEndemicSpecies2",getSpecies(objects5));
            
            List<Object> ob = organismService.getOrganismByEndemismAndIds("贵州地方特有",zIds);
            txt = txt.replaceAll("styalgaeEndemicSpeciesNum3",ob.size()+"");
            txt = txt.replaceAll("styalgaeEndemicSpecies3",getSpecies(ob));
            
            List<Object> ob1 = organismService.getOrganismByEndemismAndIds("外来",zIds);
            txt = txt.replaceAll("styalgaeAlienSpeciesNum",ob1.size()+"");
            txt = txt.replaceAll("styalgaeAlienSpecies",getSpecies(ob1));
//            List<Organism> organisms6=organismService.findAllByEndemism("中国特有",zIds);
//            num = organisms6.size();
//            txt = txt.replaceAll("styalgaeEndemicSpeciesNum1",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styalgaeEndemicSpecies1",organisms6.get(i).getName()+" "+organisms6.get(i).getLatinName()+"("+organisms6.get(i).getNamedInfo()+")"+"\n");
//            }
//            List<Organism> object7 = organismService.findAllByEndemism("贵州狭域分布",zIds);
//            num = object7.size();
//            txt = txt.replaceAll("styalgaeEndemicSpeciesNum2",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styalgaeEndemicSpecies2",object7.get(i).getName()+" "+object7.get(i).getLatinName()+"("+object7.get(i).getNamedInfo()+")"+"\n");
//            }
//
//            List<Organism> object8 = organismService.findAllByEndemism("贵州地方特有",zIds);
//            num = object8.size();
//            txt = txt.replaceAll("styalgaeEndemicSpeciesNum3",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styalgaeEndemicSpecies3",object8.get(i).getName()+" "+object8.get(i).getLatinName()+"("+object8.get(i).getNamedInfo()+")"+"\n");
//            }
    
//            //外来物种情况
//            List<Organism> organisms7=organismService.findAllByEndemism("外来",zIds);
//            num = organisms7.size();
//            txt = txt.replaceAll("styalgaeAlienSpeciesNum",num+"");
//            for (int i = 0;i < num; i++){
//                txt = txt.replaceAll("styalgaeAlienSpecies",organisms7.get(i).getName()+" "+organisms7.get(i).getLatinName()+"("+organisms7.get(i).getNamedInfo()+")"+"\n");
//            }
            
            //***********************   微生物多样性   *****************************
            List<Long> dxIds = diversityReportRepository.getDaXingZhenJunNumber("大型真菌",areaIds);
            dxIds = dxIds.size()>0?dxIds:null;
            Object[] objects2 = (Object[]) diversityReportRepository.getDaXingZhenJun(dxIds);
            for (int i = 0;i < objects2.length;i++) {
                txt = txt.replaceAll("stymacrofungiNum1",objects2[0]+"").replaceAll("stymacrofungiNum2",objects2[1]+"").replaceAll("stymacrofungiNum3",objects2[2]+"")
                    .replaceAll("stymacrofungiNum4",objects2[3]+"").replaceAll("stymacrofungiNum5",objects2[4]+"");
            }
            
            
            return txt;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    //获取物种列表
    public String getSpecies(List<Object> objects){
        String species = "";
        if(objects.size()<=0){
            return "";
        }
        for (Object o:objects){
            Object[] ob = (Object[]) o;
            species = species +ob[0]+" "+ob[1]+" ("+ob[2]+")<br>&emsp;&emsp;";
        }
        return species;
    }

    //获取百分比，包含百分号
    public String getPCT1(Object i,Object j){
        i = i!=null&&!("".equals( i ))?i:0;
        j = j!=null&&!("".equals( j ))?j:0;
        double a  =Double.valueOf( ""+i );
        double b = Double.valueOf( ""+j );
        if(b==0){
            return "100.00%";
        }
        BigDecimal bg = new BigDecimal((a*100.00)/b).setScale(2, RoundingMode.UP);
        return  bg.doubleValue()+"%";
    }
    //获取百分比，不包含百分号
    public String getPCT2(Object i,Object j){
        i = i!=null&&!("".equals( i ))?i:0;
        j = j!=null&&!("".equals( j ))?j:0;
        double a  =Double.valueOf( ""+i );
        double b = Double.valueOf( ""+j );
        if(b==0){
            return "100.00";
        }
        BigDecimal bg = new BigDecimal((a*100.00)/b).setScale(2, RoundingMode.UP);
        return  bg.doubleValue()+"";
    }
}
